Error when connecting to server: Can't connect to local MySQL server through socket '/var/lib/mysql/

解决方法一:如果没有创建/var/lib/mysql/mysql.sock
If your file my.cnf (usually in the etc folder) is correctly configured with

socket=/var/lib/mysql/mysql.sock

you can check if mysql is running with the following command:

mysqladmin -u root -p status

try changing your permission to mysql folder. If you are working locally, you can try:

sudo chmod -R 777 /var/lib/mysql/

that solved it for me

Error when connecting to server: Can't connect to local MySQL server through socket '/var/lib/mysql/_第1张图片

解决方法2:

Most likely mysql.sock does not exist in /var/lib/mysql/.

If you find the same file in another location then symlink it:

For ex: I have it in /data/mysql_datadir/mysql.sock

Switch user to mysql and execute as mentioned below:

su mysql

ln -s /data/mysql_datadir/mysql.sock /var/lib/mysql/mysql.sock

That solved my problem

 

详细资料可参考:https://stackoverflow.com/questions/4448467/cant-connect-to-local-mysql-server-through-socket-var-lib-mysql-mysql-sock

你可能感兴趣的:(mysql,mysql,报错)