【问题标题】:Moving Mysql data directory移动Mysql数据目录
【发布时间】:2018-06-30 13:00:48
【问题描述】:

我无法将我的 mysql 数据目录移动到新位置。我正在运行 Linux Mint 17、MySQL 5.7.19。我已经尝试了这两个位置的说明:

How to change MySQL data directory?

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

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

我相信我遇到了与这个问题类似的问题: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

【问题讨论】:

  • 这听起来可能很愚蠢,但是您是否重新启动了机器?我最近在权限问题上苦苦挣扎,重新启动后它们神奇地消失了。这可能与机器仍然指向内存中的旧文件有关。
  • @ibu 尝试重启,没有任何改变。
  • 您是否在服务器运行时复制了目录?这将导致数据目录损坏。
  • @Evert 我在复制之前已将其关闭。我不认为它已损坏,因为当我将新位置安装在 /var/lib/mysql 时,它运行良好。

标签: mysql


【解决方案1】:

我已经尝试了几乎所有可以在网上找到的东西。我什至阅读了手册,以进行更改。出于某种原因,将数据目录移动到除 /var/lib/mysql 之外的任何位置都会导致我出错。

我最终在这个 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

重启mysql后一切正常。

讽刺的是——符号链接没有工作

编辑

这似乎是一个错误,但提供的解决方案并不能解决我的问题:

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

这个错误是这样工作的: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/

【讨论】:

  • 有同样的问题,感谢您的努力。我以前用 MySQL 做过这个(虽然不记得版本)所以我很惊讶这次它在 5.7 上不起作用。如果您对此问题有任何更新,我想听听他们的信息。不喜欢看起来像 hack 的“mount”解决方案。
  • 不 - 我仍然使用黑客。重启mysql也不行。它以其他方式运行,并且可以用于我的目的。
【解决方案2】:

返回此错误

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    相关资源
    最近更新 更多