ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

ERROR 2002 (HY000) : Can ‘t connect to local MySQL server through socket’/var/run/mysqld/mysqld. (2) the sock ‘
The server encountered a familiar problem today
Input:

#mysql -u root -p
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

Then he searched the Internet for answers
I’m going to try each of the methods that you’ve given me
Plan 1

#ps -A|grep mysql

Display similar to:

1829 ?       00:00:00 mysqld_safe
1876 ?       00:00:31 mysqld
#kill -9 1829
  #kill -9 1876
#/etc/init.d/mysqld restart
#mysql -u root -p

His problem is solved, mine is not solved!
keep looking for
Scheme 2
Check the/etc/rc. D/init. D/mysqld status to see if the mysql has already started.
see if other permissions problems.
— — — — — — — — — — — — — —

[[email protected] beinan]#chown -R mysql:mysql /var/lib/mysql
[[email protected] beinan]# /etc/init.d/mysqld start

Start MySQL: [OK]

[[email protected] lib]# mysqladmin -uroot password ‘123456’
[[email protected] 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

His was solved, and my troubles continued, and my search continued
Scheme 3
problem solved, but max_connections=1000. He said too much, then changed it to 500, but the problem was solved.
Still won’t do
Plan 4

	/var/lib/mysql All file permissions change to mysql.mysql

No, no
Scheme 5
abstract: Solve by mysql. The problem of the sock to connect mysql main hint is that the problem can’t ‘/ TMP/mysql. The sock’ connected to the server, and PHP standard configuration is used ‘/ TMP/mysql. The sock, but some mysql installation method will mysql. The sock in/var/lib/mysql. Where the sock or other, you can modify the/etc/my CNF file to correct it, open the file, you can see the following things:

 	[mysqld] 
	socket=/var/lib/mysql .sock 

A change would be fine, but it could also cause other problems, such as the mysql program can’t be connected. Add one more point:

	[mysql ] 
  socket=/tmp/mysql .sock 

Or you can modify the configuration in php.ini to make PHP use another mysql.sock, and you can find this for yourself
or you can do it this way:

ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock

It worked. That was ln-s /var/lib/mysql. sock/TMP/mysql. sock
OK!
Solution to MySQL. Sock loss problem under MySQL 6
[ubuntu, Linux, mysqld.sock]
MySQL. Sock loss is generally caused by inconsistent configuration files. The solution:
It is judged that ordinary people did not switch to mysql user when solving the failure, which caused some permission problems. Therefore, they could not create mysql authorization table, so they could not create/TMP/mysqlm. sock and Hostname. pid files. Therefore, the summary solution is as follows (note: using root is also acceptable) :

#su mysql
$/usr/local/bin/mysql_install_db //Reconstruction authorization table
$/usr/local/bin/mysqld_safe &
$/usr/local/bin/mysql //Test
mysq>bye;
$

The file has been solved, and the new/TMP /mysql.sock and hostname.pid
have been generated.
Share source address: https://blog.csdn.net/thanklife/article/details/69225724

The fifth plan, which I borrowed from the Internet, was not successful for me. Only the sixth one succeeded!


Read More: