环境:centOS8
按照 MySQL 安装 教程操作,到下面这步出现报错:
# systemctl start mysqldJob for mysqld.service failed because the control process exited with error code.See "systemctl status mysqld.service" and "journalctl -xe" for details.
根据提示用 systemctl status mysqld.service 看了下
# systemctl status mysqld.service● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2022-02-24 16:45:08 CST; 50s ago Process: 64678 ExecStopPost=/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS) Process: 64676 ExecStart=/usr/libexec/mysqld --basedir=/usr (code=exited, status=1/FAILURE) Process: 64639 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0> Process: 64615 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 64676 (code=exited, status=1/FAILURE) Status: "Server startup in progress" Error: 13 (Permission denied)Feb 24 16:45:08 iZm5e211s4jw7g4w6pgezgZ systemd[1]: Starting MySQL 8.0 database server...Feb 24 16:45:08 iZm5e211s4jw7g4w6pgezgZ systemd[1]: mysqld.service: Main process exited, code=exited,>Feb 24 16:45:08 iZm5e211s4jw7g4w6pgezgZ systemd[1]: mysqld.service: Failed with result 'exit-code'.Feb 24 16:45:08 iZm5e211s4jw7g4w6pgezgZ systemd[1]: Failed to start MySQL 8.0 database server.
大概了解是权限问题导致启动失败 Error: 13 (Permission denied)
根据 Stack Overflow 上相关问题,查了下日志
# tail -f /var/log/mysql/mysqld.log 2022-02-24T08:59:57.903279Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.2022-02-24T08:59:57.903352Z 0 [ERROR] [MY-010119] [Server] Aborting2022-02-24T08:59:57.903491Z 0 [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.26) Source distribution.2022-02-24T09:00:45.597420Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.26) starting as process 648932022-02-24T09:00:45.604647Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 40a3dc29-9550-11ec-9b66-00163e04afe8.mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied)2022-02-24T09:00:45.604725Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13)2022-02-24T09:00:45.604750Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.2022-02-24T09:00:45.604831Z 0 [ERROR] [MY-010119] [Server] Aborting2022-02-24T09:00:45.605061Z 0 [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.26) Source distribution.
- 系统检测到是第一次启动的服务,创建了一个新的UUID
- 由于没有权限,'/var/lib/mysql/auto.cnf' 文件未创建成功,导致UUID不能写入auto.cnf
- 新服务的初始化失败,服务启动失败
**注意:日志目录可能会不一样,通常长这样 /var/log/mysql
检查了下,当前用户就是root用户,但是直接用
chown -R mysql.mysql /var/lib/mysql/
并没有成功授权
sudo chown -R mysql.mysql /var/lib/mysql/
执行之后就可以正常启动了
来源地址:https://blog.csdn.net/qq_36296794/article/details/123117151