MySQL Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)

Source: Internet
Author: User

Error reason: The socket file does not exist in the/var/lib/mysql directory.
There are two ways to connect to a MySQL server: A TCP connection, a socket file connection. Through the socket file, start the MySQL service, the MySQL service will automatically generate a sock file, the resulting sock file is placed by default--datadir=/var/lib/mysql,mysql default from/var/lib/ The MySQL directory reads the sock file.

Workaround:
1, see if/var/lib/mysql/mysql have Mysql.sock file
2, no mysql.sock, restart the MySQL service, see if there is.
3, no words, PS aux|grep mysql|grep-v ' grep ' to see the MySQL service generated sock in which directory to see if this directory is there.
4. If the MySQL service is generated in another directory, the solution is:
method One, modify the directory generated by the MySQL service, in my.cnf [mysqld] Socket
method Two, MySQL reads the sock file from the/var/lib/mysql/, establishes a soft connection, or copy comes over
method Three, modify the MySQL read directory, in MY.CNF [MySQL] socket
method Four, start the specified socket,mysql-uroot-p123456--socket= '/var/lib/mysql/mysql.sock '

Note:
1, through the socket, can only be connected on the local machine.
2, the use of-hlocalhost is through the socket, not through the network, through the netstat to see the TCP connection, you can think of MySQL and Mysql.sock file interaction, write data inside, read data from the inside.
3, the use of-h127.0.0.1 is through TCP, through the Netstat can see the connection.

MySQL Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)

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.