本文共 2401 字,大约阅读时间需要 8 分钟。
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")`
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
● mariadb.service - MariaDB 10.1 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)Active: failed (Result: exit-code) since Mon 2019-04-15 17:16:38 UTC; 4s agoProcess: 2864 ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=1/FAILURE)Process: 2841 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)Apr 15 17:16:37 xiandian systemd[1]: Starting MariaDB 10.1 database server...
Apr 15 17:16:38 xiandian mysql-prepare-db-dir[2864]: Database MariaDB is not initialized, but the directory /var/lib/mysql is not empty...e done.Apr 15 17:16:38 xiandian mysql-prepare-db-dir[2864]: Make sure the /var/lib/mysql is empty before running mysql-prepare-db-dir.Apr 15 17:16:38 xiandian systemd[1]: mariadb.service: control process exited, code=exited status=1Apr 15 17:16:38 xiandian systemd[1]: Failed to start MariaDB 10.1 database server.Apr 15 17:16:38 xiandian systemd[1]: Unit mariadb.service entered failed state.Apr 15 17:16:38 xiandian systemd[1]: mariadb.service failed.Hint: Some lines were ellipsized, use -l to show in full.`Apr 15 17:16:21 mysql-prepare-db-dir: Make sure the /var/lib/mysql is empty before running mysql-prepare-db-dir.
Apr 15 17:16:21 systemd: mariadb.service: control process exited, code=exited status=1Apr 15 17:16:21 systemd: Failed to start MariaDB 10.1 database server.Apr 15 17:16:21 systemd: Unit mariadb.service entered failed state.Apr 15 17:16:21 systemd: mariadb.service failed.`可以看到报错信息中提示数据库未初始化,但/var/lib/mysql不为空,所以无法进行初始化。
去看一下这个目录权限
ll /var/lib/ d---------. 11 mysql mysql 4096 May 4 2018 mysql
mysql权限为0,导致启动文件sock文件无法写入进去
重启赋予目录权限为755chmod 755 /var/lib/mysql/
然后再重启一下mysql服务systemctl restart mariadb.serviceps -e | grep -i mysql3191 ? 00:00:02 mysqld正常启动 转载于:https://blog.51cto.com/9103824/2378808