问题
操作系统:ubuntu 20.04/22.04(已尝试)
mysql:mysql8
磁盘:机械硬盘
修改存储路径mysql无法启动,
按照网上的说明无数次,但最终都失败了,都返回如下信息:
$ sudo systemctl start mysql
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.
我的操作:
1 sudo apt update
2 sudo apt install mysql-server mysql-client
3 sudo grep -R --color datadir /etc/mysql/*
4 sudo lsblk | grep disk
5 sudo fdisk /dev/sdd
6 sudo lsblk | grep disk
7 sudo fdisk /dev/sdd
8 sudo mkfs.ext4 -L db_data /dev/sdd1
9 sudo mkdir /db
10 sudo nano /etc/fstab
11 df -h /db
12 sudo chown mysql:mysql /db
13 sudo systemctl stop mysql
14 sudo rsync -avzh /var/lib/mysql/ /db
15 sudo nano /etc/apparmor.d/tunables/alias
16 sudo systemctl restart apparmor
17 sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
18 sudo systemctl start mysql
日志
/var/log/mysql/error.log
2022-05-02T22:51:37.712572Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /db/ is case insensitive
2022-05-02T22:51:37.713036Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-05-02T22:51:37.713175Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28-0ubuntu4) (Ubuntu).
mysqld: File './binlog.index' not found (OS errno 13 - Permission denied)
2022-05-02T22:51:38.252419Z 0 [Warning] [MY-010091] [Server] Can't create test file /db/mysqld_tmp_file_case_insensitive_test.lower-test
2022-05-02T22:51:38.252459Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28-0ubuntu4) starting as process 10542
2022-05-02T22:51:38.253869Z 0 [Warning] [MY-010091] [Server] Can't create test file /db/mysqld_tmp_file_case_insensitive_test.lower-test
2022-05-02T22:51:38.253874Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /db/ is case insensitive
2022-05-02T22:51:38.254172Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-05-02T22:51:38.254252Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28-0ubuntu4) (Ubuntu).
sudo systemctl status mysql
× mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enable>
Active: failed (Result: exit-code) since Mon 2022-05-02 22:51:38 UTC; 34min ago
Process: 10533 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited,>
Process: 10542 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Main PID: 10542 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 13 (权限不够)
CPU: 268ms
5月 02 22:51:38 ubuntu systemd[1]: mysql.service: Scheduled restart job, restart count>
5月 02 22:51:38 ubuntu systemd[1]: Stopped MySQL Community Server.
5月 02 22:51:38 ubuntu systemd[1]: mysql.service: Start request repeated too quickly.
5月 02 22:51:38 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
5月 02 22:51:38 ubuntu systemd[1]: Failed to start MySQL Community Server.
我的配置:
/etc/apparmor.d/tunables/alias
alias /var/lib/mysql/ -> /db/,
/etc/mysql/mysql.conf.d/mysqld.cnf
(/etc/mysql/my.cnf
也尝试过)
...
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
datadir = /db
...
其他尝试:
- 安装前先安装至
/var/lib/mysql
(失败) - 请勿修改
datadir
修改其他(成功)
参考:
期望您的幫助,謝謝!