Solution for mysql Service Startup but cannot be connected

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.