mysql5.7在系统重启后
首先尝试登录失败,出以下错误:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
找到mysql.sock文件,将其删除。建议将其改一个名字
mv mysql.sock mysql.sock.bak
修改完再次进入,还是同样的问题,很坑。
使用以下命令查看mysql状态
/etc/rc.d/init.d/mysqld status
表示服务未启动
mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since 六 2019-06-01 17:01:27 CST; 5min ago
Docs: man:systemd-sysv-generator(8)
Process: 1037 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
6月 01 17:01:23 localhost systemd[1]: Starting SYSV: MySQL database server....
6月 01 17:01:27 localhost mysqld[1037]: MySQL Daemon failed to start.
6月 01 17:01:27 localhost mysqld[1037]: Starting mysqld: [失败]
6月 01 17:01:27 localhost systemd[1]: mysqld.service: control process exited, code=exited status=1
6月 01 17:01:27 localhost systemd[1]: Failed to start SYSV: MySQL database server..
6月 01 17:01:27 localhost systemd[1]: Unit mysqld.service entered failed state.
6月 01 17:01:27 localhost systemd[1]: mysqld.service failed.
查看mysql错误日志(日志文件一般在 /var/log/mysqld.log,若没在此路径去/etc/my.cnf文件中查看配置)
tail mysqld.log
019-06-01T09:01:27.158699Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190601 17:01:27
2019-06-01T09:01:27.245729Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2019-06-01T09:01:27.249296Z 0 [Warning] CA certificate ca.pem is self signed.
2019-06-01T09:01:27.251165Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2019-06-01T09:01:27.251320Z 0 [Note] IPv6 is available.
2019-06-01T09:01:27.251329Z 0 [Note] - '::' resolves to '::';
2019-06-01T09:01:27.251345Z 0 [Note] Server socket created on IP: '::'.
2019-06-01T09:01:27.259003Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2019-06-01T09:01:27.259016Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory
2019-06-01T09:01:27.297759Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
此错误表示mysql服务启动时不能创建pid文件,导致启动失败
在服务器中查看文件确实不存在,手动创建mysqld目录
mkdir -p /var/run/mysqld/
创建成功后启动mysql服务
/etc/init.d/mysql start
又出错了。。。(不急,有错就有解决)
Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[失败]
继续查看日志
tail mysqld.log
2019-06-01T09:16:59.536743Z 0 [Warning] CA certificate ca.pem is self signed.
2019-06-01T09:16:59.537985Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2019-06-01T09:16:59.538134Z 0 [Note] IPv6 is available.
2019-06-01T09:16:59.538143Z 0 [Note] - '::' resolves to '::';
2019-06-01T09:16:59.538157Z 0 [Note] Server socket created on IP: '::'.
2019-06-01T09:16:59.538612Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-06-01T09:16:59.567894Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2019-06-01T09:16:59.567914Z 0 [ERROR] Can't start server: can't create PID file: Permission denied
2019-06-01T09:16:59.571430Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190601 17:16:59
2019-06-01T09:16:59.613126Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
错误原因为:/var/run/mysqld/目录的拥有者为root,mysql不能在其中创建文件
使用如下命令修改目录使用者
先查看目录是否存在
ls -ld /var/run/mysqld/
chown mysql.mysql /var/run/mysqld/
修改后重启mysql服务
/etc/init.d/mysqld start
启动成功,终于又可以登录我们的个人隐私库了???。
请忽略图片中密码错误提示,最近记性不好,打扰了!
系统重启后mysql未启动
启动使用如下命令
systemctl start mysqld
配置开启启动
systemctl enable mysqld
systemctl list-unit-files | grep mysqld
设置完即可!!!