Solution to connect MySQL hint can ' t connect to local MySQL server through socket
September 6, 2013 aiezu Comment Read review
MySQL, mysqldump,mysqladmin,php connection MySQL service often prompts the following error:
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/<span class= ' wp_keywordlink_affiliate ' ><a href= "Http://www.aiezu.com/tag/mysql-2" title= "View all articles in MySQL" target= "_blank" >mysql</a></ Span>/mysql.sock ' (2)
1 |
ERROR 2002 (HY000): Can' t Connect to local MySQL server through socket '/var/lib/ MySQL / MySQL . sock' (2) |
This is due to the mysql.sock location of the socket file that modifies the MySQL service, which is caused by the inability to connect to the MySQL service via the MySQL socket file, the following are the specific workarounds:
1. View the location of the socket file for the MySQL service:
The location of the MySQL socket file is set in/etc/my.cnf, and the CAT/ETC/MY.CNF content is as follows:
[Mysqld] Datadir=/storage/db/mysql socket=/storage/db/mysql/mysql.sock user=mysql
1 2 3 4 |
[mysqld] DataDir = / Storage / DB / MySQL Socket = / Storage / DB / MySQL / MySQL . sock User = MySQL |
Where the socket is equal to the location of the socket file, we just modify the my.cnf file, tell MySQL,mysqldump,mysqladmin The MySQL service socket location is available.
2. Modify the My.cnf file:
Add the following in the/etc/my.cnf file and restart the MYSQLS service to resolve the Mysql,mysqldump,mysqladmin "can" T connect to local MySQL server Through socket '/var/lib/mysql/mysql.sock ' "Problem:
[Mysqld] Datadir=/storage/db/mysql socket=/storage/db/mysql/mysql.sock [MySQL] Socket=/storage/db/mysql/mysql.sock [Mysqldump] socket=/storage/db/mysql/mysql.sock [mysqladmin] Socket=/storage/db/mysql/mysql.sock
1 2 3 4 5 6 7 8 9 10 11 12 |
[mysqld] DataDir = / Storage / DB / MySQL Socket = / Storage / DB / MySQL / MySQL . sock [mysql] Socket = / Storage / DB / MySQL / MySQL . sock [mysqldump] Socket = / Storage / DB / MySQL / MySQL . sock [mysqladmin] Socket = / Storage / DB / MySQL / MySQL . sock |
Can ' t connect to local MySQL server through socket