Solve the login error after installing mysql in linux in detail: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Solve the login error after installing mysql in linux in detail: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

The connection to localhost is usually performed through a Unix domain socket file, which is usually automatically generated in /tmp/mysql.sock, so we need the mysql.sock socket when we log in to mysql. But after installing it, I found that there is no mysql.sock file under /tmp, so don’t panic, just be sure~
insert image description here

Solution 1

First, you can use "find / -name 'mysql.sock'" to find out whether mysql.sock exists in the current environment,insert image description here

If msyql.sock is found, and it is not under /tmp, just build a soft link directly. Don't think about copying mysql.sock to /tmp, this file cannot be operated, otherwise an error will be reported cp: Unable to open "mysql.sock" Read data: No such device or address.
If there is no mysql.sock file in the local environment, please refer to solution 2.

ln -s /tmp/mysql.sock 路径/找到的mysql.sock

Solution 2

If you don’t find mysql.sock, then find the my.cnf file, usually in /etc/my.cnf, and then modify the information that generates the mysql.sock path in it, save it, and log in again to get it done. However~ some big brothers may not even have the file my.cnf, it is amazing and crashes, then skip this method and see solution 3

socket = /tmp/mysql.sock

Solution 3

If there is no my.cnf file, it is not necessary to log in to mysql through a local socket. You can also log in to mysql by specifying an IP address. Use tcp to connect to mysql instead of using a local sock

mysql -h127.0.0.1 -u root -p

If you still cannot log in by specifying the ip, or report the following error
insert image description here
, then modify the my.cnf file, comment out the following line, save it and log in again.

#bind-address           = 127.0.0.1

insert image description here

Disgusting is back again, some big brothers don’t have the my.cnf file in the first place, so change it! Hahaha, so the method of specifying the ip still doesn’t work. In the end, none of the above can solve your problem, so you can only use the last nirvana below

last resort nirvana

systemctl status mysqld   #查看mysql的服务状态
systemctl restart mysqld  #重启mysql服务

insert image description here

mysql -u root -p   #重新登录

insert image description here

Great work, get it done! Great, right? The more powerful the killing technique is, the simpler it is, hahaha... burp~

Guess you like

Origin blog.csdn.net/qq_43221829/article/details/131463732