报错信息

登陆数据库报错:`

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.


查看服务状态信息:`systemctl status mariadb.service

● 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 ago
Process: 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=1
Apr 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 xiandian mysql-prepare-db-dir: Database MariaDB is not initialized, but the directory /var/lib/mysql is not empty, so initialization cannot be done.

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=1
Apr 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文件无法写入进去
重启赋予目录权限为755
chmod 755 /var/lib/mysql/
然后再重启一下mysql服务
systemctl restart mariadb.service
ps -e | grep -i mysql
3191 ? 00:00:02 mysqld
正常启动