Mysql

移動數據目錄後 MySQL 伺服器不啟動

  • March 22, 2021

我正在嘗試將 MySQL 的數據目錄移動到 odroid(類似樹莓的迷你電腦)上的外部驅動器。

我正在使用 Ubuntu 14.04。

我更改了所有配置文件中的路徑,其中包含/var/lib/mysql並移動了新驅動器上的所有 mysql 文件夾。

該服務不再啟動,我不知道如何解決。

以下是所有更改的路徑:

root@odroid-server:/etc# grep -rnw '/etc' -e "/var/lib/mysql"
root@odroid-server:/etc# grep -rnw '/etc' -e "/media/md0/mysql"
/etc/apparmor.d/abstractions/mysql:12:   /media/md0/mysql{,d}/mysql{,d}.sock rw,
/etc/apparmor.d/tunables/alias:16:# alias /media/md0/mysql/ -> /home/mysql/,
/etc/apparmor.d/usr.sbin.mysqld:49:  /media/md0/mysql/ r,
/etc/apparmor.d/usr.sbin.mysqld:50:  /media/md0/mysql/** rwk,
/etc/apparmor.d/usr.sbin.mysqld:53:  /media/md0/mysql-files/ r,
/etc/apparmor.d/usr.sbin.mysqld:54:  /media/md0/mysql-files/** rwk,
/etc/apparmor.d/usr.sbin.mysqld:57:  /media/md0/mysql-keyring/ r,
/etc/apparmor.d/usr.sbin.mysqld:58:  /media/md0/mysql-keyring/** rwk,
/etc/imscp/imscp.conf:37:DATABASE_DIR = /media/md0/mysql
/etc/mysql/mysql.conf.d/mysqld.cnf:36:datadir           = /media/md0/mysql
/etc/mysql/mysql.conf.d/mysqld.cnf:92:# InnoDB is enabled by default with a 10MB datafile in /media/md0/mysql/.
/etc/mysql/mysql.conf.d/mysqld.cnf:98:# chroot = /media/md0/mysql/

然後啟動服務:

root@odroid-server:/etc# service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

我嘗試了該命令以獲取更多詳細資訊,我可以看到它仍然使用舊的 mysql 數據目錄。

root@odroid-server:/etc# journalctl -xe
Nov 18 13:06:45 odroid-server systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Nov 18 13:06:45 odroid-server mysql-systemd-start[24276]: MySQL data dir not found at /var/lib/mysql. Please create one.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Control process exited, code=exited status=1
Nov 18 13:06:45 odroid-server systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Unit entered failed state.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Nov 18 13:06:45 odroid-server systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Start request repeated too quickly.
Nov 18 13:06:45 odroid-server systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.

也許有一些命令可以將配置文件重新載入回 ram?

我剛剛找到了一個解決方案(發生在我身上的幾年之後)。

問題只是 ubuntu 伺服器附帶了惡意軟體apparmor。我只是在檢查後才注意到dmesg。為了擺脫它,我只是跑了

sudo apt remove --purge apparmor -y

這使得 mysql 從我的新 mysql datadir 開始(並修復了其他問題)。

從評論:

只需符號連結/var/lib/mysql到新目錄。

製作符號連結是移動重要文件和目錄的一種快速、簡單的方法。無需更改任何配置,並且需要跟踪的文件最少。

引用自:https://serverfault.com/questions/815729