已经碰见过两次这个问题,上一次解决到现在因该快两个月了,现在又出现这个问题记录下来分享:
操作系统:阿里云centos 7.2
目录
1. 首先查看mysql状态
[root@SHUN ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@SHUN ~]# systemctl status mysqld
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Thu 2018-07-05 09:38:28 CST; 3 weeks 1 days ago
Main PID: 19350 (code=exited, status=0/SUCCESS)
Jul 05 09:34:29 SHUN systemd[1]: mysqld.service holdoff time over, scheduling restart.
Jul 05 09:34:29 SHUN systemd[1]: Starting MySQL Community Server...
Jul 05 09:34:29 SHUN mysqld_safe[19350]: 180705 09:34:29 mysqld_safe Logging to '/var/log/mysqld.log'.
Jul 05 09:34:29 SHUN mysqld_safe[19350]: 180705 09:34:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jul 05 09:34:30 SHUN systemd[1]: Started MySQL Community Server.
Jul 05 09:38:27 SHUN systemd[1]: Stopping MySQL Community Server...
Jul 05 09:38:28 SHUN systemd[1]: Stopped MySQL Community Server.
2.继续查看状态:
[root@SHUN ~]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
3.按照端口进行登录:
[root@SHUN ~]# mysql -uroot -p -S /var/lib/mysql1/mysql.sock -P3306
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql1/mysql.sock' (2)
4.查看mysql的network ID:
[root@SHUN ~]# ps -A|grep mysql
15956 ? 00:00:00 mysqld_safe
16081 ? 00:13:15 mysqld
[root@SHUN ~]# kill -9 15956
[root@SHUN ~]# kill -9 16081
[root@SHUN ~]# ps -ef |grep mysql
mysql 18992 1 0 09:24 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 19117 18992 0 09:24 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid
root 19152 18555 0 09:30 pts/0 00:00:00 grep --color=auto mysql
5.利用mysql 客户端进行关闭:
[root@SHUN ~]# mysqladmin -h127.0.0.1 -uroot -p shutdown
Enter password:
mysqladmin: connect to server at '127.0.0.1' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
6.折腾了半天还是没有成功kill掉mysql
[root@SHUN ~]# systemctl stop mysql.service
[root@SHUN ~]# ca /var/lib/mysql
-bash: ca: command not found
[root@SHUN ~]# ca /var/lib/
-bash: ca: command not found
[root@SHUN ~]# cd /var/lib/
[root@SHUN lib]# ll
6.最后终于可以重新启动了用了一下命令:
[root@SHUN ~]# mysqld_multi --defaults-extra-file=/etc/my.cnf --user =root start 1,2
[root@SHUN ~]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
[root@SHUN ~]# mysql -uroot -p -S /var/lib/mysql1/mysql.sock -P3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.39-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>