Can't connect to local MySQL server through socket '/tmp/MySQL. Sock' (2)

Source: Internet
Author: User

I encountered a problem connecting to the MySQL database today: Can't connect to local MySQL server through socket '/tmp/MySQL. Sock' (2)

 

Refer to online related methods, including: (http://blog.csdn.net/lmss82/archive/2009/08/05/4414178.aspx)

Solution 1.
1. # ps-A | grep MySQL
Display is similar:
1829? 00:00:00 mysqld_safe
1876? 00:00:31 mysqld
2. # Kill-9 1829
3. # Kill-9 1876
4. #/etc/init. d/MySQL restart
5. # mysql-u root-P
 
His troubles have been solved, and I have not solved it yet!
 
Continue searching
Solution 2
Check/etc/rc. d/init. d/mysqld status to see if m y s q l has been started.
Check whether the permission is correct.
Bytes ------------------------------------------------------------------------------------
[Root @ localhost beinan] # chown-r MYSQL: MySQL/var/lib/MySQL
[Root @ localhost beinan] #/etc/init. d/mysqld start
Start MYSQL: [OK]
[Root @ localhost lib] # mysqladmin-uroot password '123'
[Root @ localhost lib] # mysql-uroot-P
Enter password:
Welcome to the MySQL monitor. commands end with; or/g.
Your MySQL connection ID is 3 to server version: 4.1.11

Type 'help; 'or'/H' for help. type'/C' to clear the buffe
 
He has also solved the problem. I am still in trouble and continue to look for it.
 
Solution 3
After the problem is solved, it turns out that max_connections = 1000 has said too much, and then he changed it to 500 and said too much, but he had no choice but to delete the problem.
 
Still not good
Solution 4

/Var/lib/MySQL change all file permissions to MySQL. MySQL

No.
 
Solution 5
Abstract: MySQL cannot be used. the main cause of sock connection to MySQL is that it cannot pass '/tmp/MySQL. the sock is connected to the server, and the PHP standard configuration has been used '/tmp/MySQL. sock, but some MySQL installation methods will be MySQL. put sock in/var/lib/MySQL. sock or somewhere else, you can modify/etc/My. modify the CNF file and open the file. You can see the following:
[MySQL D]
Socket =/var/lib/MySQL. Sock
Just change it, but it will also cause other problems. For example, if the MySQL program cannot be connected, add one more point:
[MySQL]
Socket =/tmp/MySQL. Sock
You can also modify the configuration in PHP. ini to connect PHP to another mysql. Sock.
  
Or use the following method:
Ln-S/var/lib/MySQL. Sock/tmp/MySQL. Sock

If the call succeeds, Ln-S/var/lib/MySQL. Sock/tmp/MySQL. Sock

OK!

 

But not found in my systemMySQL. SockFile, onlyMysqld. SockFile,/var/run/mysqld. Sock

As a result, follow the above practice: ln-S/var/run/mysqld. Sock/tmp/MySQL. Sock

In this way, you can connect to the database normally.

 

(Http://blog.chinaunix.net/u1/43706/showart_351145.html)

Mysql_real_connect () tries to establish to runhostOneMySQLA connection to the database engine. The original function is:

   MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned int client_flag)

I want to compile a program to remotely connect to a MySQL database. I did a test on the local database and found that the connection can be normal when the second parameter of mysql_real_connect () is set to "localhost, the connection fails when it is changed to the IP address "192.168.100.2" of the machine. The original sentence I wrote in the program is mysql_real_connect (MySQL, "192.168.100.2", "root", "", "mydns", 0, null, 0 ). At first, I thought I had to write the sixth parameter port number after changing "localhost" to "192.168.100.2", but it still didn't work. Because I did it on Linux, I may need to write the seventh parameter unix_socket, but the result still does not work. So I went to Google to find a solution and found that to remotely connect to MySQL, I needed to set the remote connection permission for the specified account of MySQL. In my program, we need to set this permission for root. It turns out that my previous connection failure was caused by this reason. However, the problem is that the method of widely posting on the Internet is wrong. After I did it, I still couldn't do it. I finally asked my classmates to solve it. I hope that you will not be misled. A MySQL database contains a user table that contains all accounts and their permissions and features. Corresponding to the "root" User item in my User table, two items are found: localhost and localhost. localdomain. We only need to change 'localhost' to '%' to allow all remote machines to log on to the MySQL server as the root account. You can also change 'localhost' to an IP address so that you can log on to the MySQL server on the machine where the address is located.. These are all correct, but the method for changing the host item is widely mentioned on the Internet. The method is to use the update statement to change the host item of the specified user item. To add a new account for remote access, use the insert statement. The fact is that this doesn't work at all. As I have done, the table has changed, but it still cannot be connected. Later, I learned after inquiry that, in order to change it, I had to use the following statement: grant all privileges on mydns. * To 'root' @ '%'; to change the permissions of the root account. This is also true if a new account is added. This table must be special and cannot be operated using common SQL statements. If your account has a password, add identified by '***' (* your account password. It took an afternoon to solve this problem. It took a lot of twists and turns out to reduce your detours.
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.