Solution for mysql Service Startup but cannot be connected
How can I solve the problem that mysql service is started but cannot be connected?
Logon error:
root@localhost:~# 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@localhost:~# service mysqld restart Shutting down MySQL.. [ OK ] Starting MySQL. [ OK ] root@localhost:~# mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Cause analysis:
The reason is unknown.
Solution 1:
root@localhost:~# find / -name mysql.sock /tmp/mysql.sock root@localhost:~# mysql -u root -p -S /tmp/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.15-log Source distribution Copyright (c) 2000, 2011, 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>
Solution 2:
Root @ localhost :~ # Find/-name mysql. sock/tmp/mysql. sock root @ localhost :~ # Vi/etc/my. cnf [mysqld] datadir =/var/lib/mysqlsocket =/var/lib/mysql. sockuser = mysql # Default to using old password format for compatibility with mysql 3.x# clients (those using the mysqlclient10 compatibility package ). old_passwords = 1 # Disabling symbolic-links is recommended to prevent assorted security risks; # to do so, uncomment this line: # symbolic-links = 0 # Add the following code to [mysql] socket =/tmp/mysq L. sock [mysqld_safe] log-error =/var/log/mysqld. logpid-file =/var/run/mysqld. pidroot @ localhost :~ # Mysql-u root-pEnter password: Welcome to the MySQL monitor. commands end with; or \ g. your MySQL connection id is 3 Server version: 5.6.15-log Source distributionCopyright (c) 2000,201 1, Oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. other names may be trademarks of their respectiveowners. type 'help; 'or' \ H' for help. type '\ C' to clear the current input statement. mysql>
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.