![如何移动 MySQL 的默认存储位置?](https://linux22.com/image/1191279/%E5%A6%82%E4%BD%95%E7%A7%BB%E5%8A%A8%20MySQL%20%E7%9A%84%E9%BB%98%E8%AE%A4%E5%AD%98%E5%82%A8%E4%BD%8D%E7%BD%AE%EF%BC%9F.png)
背景信息:
APT 默认安装的 MySQL 服务器 8.0 占据了我的根分区。
因此,我最近在系统上安装了一个新驱动器,用于存储大型数据集,特别是大型 MySQL 数据库。我已将该驱动器添加到“fstab”,并确认它会在启动时自动安装。
我的问题:
我希望将默认的“datadir”移动到该已安装的驱动器,但是按照原始 MySQL 文档中的说明执行后,mysqld --initialize --user=mysql --datadir=/mnt/new_drive
MySQL 错误日志显示创建的文件夹“不可用”。我也尝试了此Digital Ocean 教程和这个Youtube 视频没有运气。
终端输出:
(base) ➜ ~ sudo chown mysql:mysql /mnt/data/mysql/
(base) ➜ ~ sudo mysqld --initialize-insecure --user=mysql --datadir=/mnt/data/mysql/data
2022-12-05T17:53:54.587829Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31-0ubuntu0.22.04.1) initializing of server in progress as process 31763
2022-12-05T17:53:54.588736Z 0 [ERROR] [MY-010174] [Server] Can't change data directory owner to mysql
2022-12-05T17:53:54.588738Z 0 [ERROR] [MY-013236] [Server] The designated data directory /mnt/data/mysql/data/ is unusable. You can remove all files that the server added to it.
2022-12-05T17:53:54.588782Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-12-05T17:53:54.588920Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31-0ubuntu0.22.04.1) (Ubuntu).
更新 1:
按照本文问题部分所述的步骤 1 - 5 进行操作后AskUbuntu 主题,该mysqld --initialize --user=mysql --datadir=/mnt/new_drive
步骤似乎已成功完成。因此权限问题可能与 AppArmor 有关。但现在服务器无法启动。
日志/var/log/mysql/error.log
显示以下内容:
2022-12-05T19:42:05.982975Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31-0ubuntu0.22.04.1) initializing of server in progress as process 41772
2022-12-05T19:42:06.022751Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-12-05T19:42:06.164363Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-12-05T19:42:07.137874Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: <random password>
当我尝试启动 MySQL 服务时发生了这种情况。
(base) ➜ ~ sudo service mysql status
× mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2022-12-05 14:46:11 EST; 6s ago
Process: 42159 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
CPU: 5ms
Dec 05 14:46:11 Raza systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Dec 05 14:46:11 Raza systemd[1]: Stopped MySQL Community Server.
Dec 05 14:46:11 Raza systemd[1]: mysql.service: Start request repeated too quickly.
Dec 05 14:46:11 Raza systemd[1]: mysql.service: Failed with result 'exit-code'.
Dec 05 14:46:11 Raza systemd[1]: Failed to start MySQL Community Server.
系统信息:
Ubuntu 22.04 MySQL 服务器 8.0