我无法将mysql数据目录移动到新位置。我正在运行Linux Mint 17,MySQL 5.7.19。我在这两个地方尝试了说明:
How to change MySQL data directory?
这个答案: https://stackoverflow.com/a/10209282/7850358
我相信我遇到了与此问题类似的问题:https://dba.stackexchange.com/questions/101732/how-do-i-move-a-mysql-data-directory-to-an-external-hard-drive
我将数据从/var/lib/mysql
发送到/media/mike/DataBase
。该目录存在,并在/etc/mysql/mysql.conf.d/mysqld.cnf
中正确指定,我在/etc/apparmor.d/tunables/alias
中创建了一个别名。我确保该文件夹的权限是正确的:drwx------ 11 mysql mysql 4096 Jan 21 16:52 mysql
。
我重启apparmor,没问题。 我重新启动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
答案 0 :(得分:1)
我已经尝试了一些我能在网上找到的东西。我甚至阅读了手册,进行了更改。出于某种原因,将数据目录移动到任何位置但/ var / lib / mysql会导致错误。
我最终运气好了这个黑客: 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
重新启动mysql后,一切正常。
讽刺的是 - 符号链接没有工作
编辑
这似乎是一个错误,但提供的解决方案并不能解决我的问题:
https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1574782 https://forums.mysql.com/read.php?11,653198,653198#msg-653198
这个bug的工作原理如下:启动时MySQL会查找/var/lib/mysql/
和/var/lib/mysql/mysql
目录的存在。提供的解决方案是保留/var/lib/mysql
和/var/lib/mysql/mysql
目录,但删除内容并将新的datadir路径添加到apparmor配置文件(/etc/apparmor.d/usr.sbin.mysqld
)并重新加载(/etc/init.d/apparmor reload
)
但重复一下,虽然看起来我有同样的问题(MySQL一直在/var/lib/mysql
寻找数据库),唯一对我有用的解决方案是将数据目录挂载到/var/lib/mysql/
。
答案 1 :(得分:-1)
返回这个错误
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