Can 't connect to local MySQL through socket' and tmp and mysql. sock 'Solution

  • 2021-11-14 07:23:22
  • OfStack

Error message:

ERROR 2002: Can 't connect to local MySQL server through socket'/tmp/mysql. sock '(111)

Solution:


/usr/local/mysql/bin/mysqladmin -u root > -S /var/lib/mysql/mysql.sock password 'your.passwd'

Or make a soft connection


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

Reason:

In fact, the prompt can't find the/tmp/mysql. sock sometimes doesn't have this file in the/tmp directory, but the startup command is wrong.


/usr/local/mysql/bin/mysql -u root -p
/usr/local/mysql/bin/mysqld --user=mysql&
/usr/local/mysql/bin/mysqld --user=root&
/usr/local/mysql/bin/mysqld_safe --user=root&
/usr/local/mysql/bin/mysqld_safe --user=mysql&
/usr/local/mysql/bin/safe_mysqld--uer=root&( Attention safe_mysqld And mysqld_safe Is different, & Denote mysql Run in the background )

Error message:

STOPPING server from pid file /usr/local/mysql/data/localhost.localdomain.pid 060304 11:46:21 mysqld ended

Solution:

This is a privilege problem. My mysql directory belongs to root users and root group. It is no problem to start with mysqld_safe instead. You only need to pay attention to these mysql, safe_mysqld, mysqld_safe, mysqld and mysqladmin. Try several times more. In fact, sometimes mysql has started normally. Check whether mysql starts the command


ps -aux | grep mysqld

You'll see something like this


mysql 6394 0.0 1.5 10528 992 pts/3 S 16:16 0:00
/usr/local/mysql/mysql 6395 0.0 1.5 10528 992 pts/3 S 16:16 0:00
/usr/local/mysql/mysql 6396 0.0 1.5 10528 992 pts/3 S 16:16 0:00
/usr/local/mysql/root 6422 0.0 1.1 2408 732 pts/3 S 16:20 0:00 grep mysql

See if mysql is listening for port commands


netstat -tl | grep mysql

You'll see something like this


tcp 0 0 *:mysql *:* LISTEN

Summarize


Related articles: