解决:error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

在使用

deamon@deamon-H55M-S2:/usr/bin$ mysqladmin -u root -p shutdown

关闭MySQL之后试图通过:

deamon@deamon-H55M-S2:/usr/bin$ mysqld_safe &

来重启服务器,发现重启失败,显示权限不够:

/usr/bin/mysqld_safe: 548: /usr/bin/mysqld_safe: cannot create /var/lib/mysql/mysqld_safe.pid: Permission denied

于是加上sudo:

deamon@deamon-H55M-S2:~$ sudo mysqld_safe&
[4] 7998 [4]+ Stopped sudo mysqld_safe
deamon@deamon-H55M-S2:~$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

然后就出现了如题所示的错误。

解决方法是将用户切换成root,再重新启动。

deamon@deamon-H55M-S2:~$ su -
Password:
root@deamon-H55M-S2:~# mysqld_safe &
[1] 8155
root@deamon-H55M-S2:~# 2016-11-29T11:50:50.182755Z mysqld_safe Logging to syslog.
2016-11-29T11:50:50.186438Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2016-11-29T11:50:50.209538Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql root@deamon-H55M-S2:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2016, 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>

此时将用户切换回原非root用户,mysql还可正常使用。至此该问题解决。

上一篇:关于Mysql错误:./bin/mysqld_safe --user=mysql& [1] 32710 121003 16:40:22 mysqld_safe Logging to '/var/log/mysqld.log'. 121003 16:40:22 mysqld_s


下一篇:ubuntu 下安装 mysql 启动报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)