简体   繁体   English

移动Mysql数据目录

[英]Moving Mysql data directory

I am having trouble moving my mysql data directory to a new location.我在将 mysql 数据目录移动到新位置时遇到问题。 I am running Linux Mint 17, MySQL 5.7.19.我正在运行 Linux Mint 17、MySQL 5.7.19。 I have tried the instructions in these two locations:我已经尝试了这两个位置的说明:

How to change MySQL data directory? 如何更改 MySQL 数据目录?

This answer: https://stackoverflow.com/a/10209282/7850358这个答案: https : //stackoverflow.com/a/10209282/7850358

and this guide: https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04和本指南: https : //www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04

I believe I am having a similar problem as this question: https://dba.stackexchange.com/questions/101732/how-do-i-move-a-mysql-data-directory-to-an-external-hard-drive我相信我遇到了与这个问题类似的问题: https : //dba.stackexchange.com/questions/101732/how-do-i-move-a-mysql-data-directory-to-an-external-hard-开车

I rsync'ed the data from /var/lib/mysql to /media/mike/DataBase .我将数据从/var/lib/mysql同步到/media/mike/DataBase The directory exists, and is properly specified in the /etc/mysql/mysql.conf.d/mysqld.cnf , and I created an alias in /etc/apparmor.d/tunables/alias .该目录存在,并在/etc/mysql/mysql.conf.d/mysqld.cnf正确指定,我在/etc/apparmor.d/tunables/alias创建了一个别名。 I made sure the permissions on the folder were correct: drwx------ 11 mysql mysql 4096 Jan 21 16:52 mysql .我确保文件夹的权限正确: drwx------ 11 mysql mysql 4096 Jan 21 16:52 mysql

I restart apparmor, no problems.我重启apparmor,没问题。 I restart the mysql server - I get this:我重新启动 mysql 服务器 - 我得到这个:

Thudbucket mike # sudo systemctl start mysql
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
Thudbucket mike # systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Sun 2018-01-21 17:10:34 EST; 12s ago
  Process: 22295 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 22288 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 22295 (code=exited, status=1/FAILURE);         : 22296 (mysql-systemd-s)
   CGroup: /system.slice/mysql.service
           └─control
             ├─22296 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─22332 sleep 1

Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.308875Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.308930Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.453972Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server opti
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.454033Z 0 [Warning] Can't create test file /media/mike/DataBase/mysql/Thudbucket.lower-test
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.454054Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.19-0ubuntu0.16.04.1) starting as process 22295 ...
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455725Z 0 [Warning] Can't create test file /media/mike/DataBase/mysql/Thudbucket.lower-test
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455735Z 0 [Warning] Can't create test file /media/mike/DataBase/mysql/Thudbucket.lower-test
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455760Z 0 [ERROR] failed to set datadir to /media/mike/DataBase/mysql/
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455774Z 0 [ERROR] Aborting
Jan 21 17:10:34 Thudbucket systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE

I've tried just about everything I could find online.我已经尝试了几乎所有可以在网上找到的东西。 I even read the manual, for a change.我什至阅读了手册,以进行更改。 For some reason, moving the data directory to any location but /var/lib/mysql results in errors for me.出于某种原因,将数据目录移动到任何位置,但 /var/lib/mysql 会导致我出错。

I ultimately had better luck with this hack: https://askubuntu.com/a/663945/785778我最终在这次 hack 中获得了更好的运气: https : //askubuntu.com/a/663945/785778

## copy with permissions intact:
rsync -avzh /var/lib/mysql /path/to/new/place

## back up original
mv /var/lib/mysql /var/lib/_mysql 

## create a new empty directory in place of old:
mkdir /var/lib/mysql 

## bind mount the new location to the old:
mount -B /path/to/new/place /var/lib/mysql

After restarting the mysql, everything worked fine.重启mysql后,一切正常。

Ironically - symbolic linking did not work具有讽刺意味的-象征性的链接没有工作

EDIT编辑

This appears to be a bug, but the provided solution doesn't resolve the issue for me:这似乎是一个错误,但提供的解决方案并没有解决我的问题:

https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1574782 https://forums.mysql.com/read.php?11,653198,653198#msg-653198 https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1574782 https://forums.mysql.com/read.php?11,653198,653198#msg-653198

The bug works like this: MySQL at startup looks for the presence of the /var/lib/mysql/ and /var/lib/mysql/mysql directories.该错误的工作原理如下:MySQL 在启动时查找/var/lib/mysql//var/lib/mysql/mysql目录的存在。 The solution provided to leave the /var/lib/mysql and /var/lib/mysql/mysql directories but remove the contents and add the new datadir path to the apparmor configuration file ( /etc/apparmor.d/usr.sbin.mysqld ) and reload it ( /etc/init.d/apparmor reload ).提供的解决方案是保留/var/lib/mysql/var/lib/mysql/mysql目录但删除内容并将新的 datadir 路径添加到 apparmor 配置文件 ( /etc/apparmor.d/usr.sbin.mysqld ) 并重新加载它 ( /etc/init.d/apparmor reload )。

But to repeat, while it appears I have the same issue (MySQL keeps looking for the datadir at /var/lib/mysql ), the only solution that worked for me was to mount the data directory at /var/lib/mysql/ .但是重复一遍,虽然看起来我有同样的问题(MySQL 一直在/var/lib/mysql寻找 datadir ),但对我有用的唯一解决方案是将数据目录挂载在/var/lib/mysql/

Return this error返回此错误

2021-02-12T19:02:55.910704Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2021-02-12T19:02:55.910710Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
2021-02-12T19:02:55.910731Z 0 [ERROR] Aborting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM