问题背景
修改MySQL二进制日志目录时,已经创建了新的目录且授权。
mkdir -pv /mysql/log/
chown -R /mysql/log/
并且修改了配置文件:vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
log_bin=/mysql/log/binlog
此时重启服务时报错。
问题呈现
[root@rocky154 ~]# ll /mysql/log
total 8
-rw-r-----. 1 mysql mysql 157 Aug 3 22:38 binlog.000001
-rw-r-----. 1 mysql mysql 25 Aug 3 22:38 binlog.index
[root@rocky154 ~]# cat /etc/my.cnf.d/mysql-server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
log_bin=/mysql/log/binlog
[root@rocky154 ~]# systemctl restart mysqld.service
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.
查看MySQL服务状态如下:
[root@rocky154 ~]# systemctl status mysqld.service
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2024-08-03 22:45:50 CST; 3min 9s ago
Process: 21077 ExecStopPost=/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
Process: 20868 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 21076 ExecStart=/usr/libexec/mysqld --basedir=/usr (code=exited, status=1/FAILURE)
Process: 21039 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
Process: 21014 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 21076 (code=exited, status=1/FAILURE)
Status: "Server shutdown complete"
Error: 13 (Permission denied)
Aug 03 22:45:50 rocky154 systemd[1]: mysqld.service: Succeeded.
Aug 03 22:45:50 rocky154 systemd[1]: Stopped MySQL 8.0 database server.
Aug 03 22:45:50 rocky154 systemd[1]: Starting MySQL 8.0 database server...
Aug 03 22:45:50 rocky154 systemd[1]: mysqld.service: Main process exited, code=exited, status=1/FAILURE
Aug 03 22:45:50 rocky154 systemd[1]: mysqld.service: Failed with result 'exit-code'.
Aug 03 22:45:50 rocky154 systemd[1]: Failed to start MySQL 8.0 database server.
查看MySQL日志查找原因:
[root@rocky154 ~]# cat /var/log/mysql/mysqld.log
2024-08-03T14:45:49.756716Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.36).
2024-08-03T14:45:50.143809Z 0 [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.36) Source distribution.
2024-08-03T14:45:50.535639Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2024-08-03T14:45:50.535691Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.36) starting as process 21076
mysqld: File '/mysql/log/binlog.index' not found (OS errno 13 - Permission denied)
2024-08-03T14:45:50.537511Z 0 [ERROR] [MY-010119] [Server] Aborting
2024-08-03T14:45:50.537594Z 0 [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.36) Source distribution.
解决方案:
参考文章:https://blog.csdn.net/qq_34901049/article/details/133946249
- 需要关闭 SELINUX
#临时关闭
setenforce 0
#永久关闭 SELINUX
vim /etc/selinux/config
SELINUX=disabled