$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
This error occurs because MySQL has not been started. To verify this guess, you can turn on the activity monitor and search mySQld, which cannot be found. Since I took the screenshot after fixing the problem myself, the mySQld process was already started when I searched.
Or type a command to view mysql.server Status
$ mysql.server status
/usr/local/mysql/support-files/mysql.server: line 365: pidof: command not found
ERROR! MySQL is not running
As you can see, MySQL is not running. Since MySQL isn’t running, we definitely need to start MySQL.
Second, MySQL startup also reported an error
$mysql.server start
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/XXXX.local.pid).
The boot report is wrong, is the permission not enough?So first change the permissions of /usr/local/var/mysql
sudo chown -R _mysql:mysql /usr/local/var/mysql
Once the permissions are resolved, test it with SUdo and restart it
3. Start sudo
$ sudo mysql.server start
Password:
Starting MySQL
.. SUCCESS!
Surprisingly, MySQL started successfully, and then logged in again
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21-log Homebrew
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Summary: The problem of Can’t connect to local MySQL Server through socket is caused by MySQL not being started. The Server Quit without updating The PID file is due to permissions problem, which is solved and The first problem is solved accordingly.
Of course, due to different environment configuration and different installation methods, there will be some differences in the solution, but the cause of the problem should be the same. I am a Mac, homebrew installed mysql, through this method, successfully solved the problem.
Refer to the information on StackOverflow:
MySql server startup error ‘The server quit without updating PID file ‘
For a newbie: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’
Read More:
- It can’t connect to local MySQL server through socket ‘/ tmp/ mysql.sock ‘(2) “;
- MySQL restart error the server quit without updating PID file
- Failed to connect to Mir:Failed to connect to server socket:No such file or directory
- MySQL server PID file could not be found!
- MYSQL login error: mysqladmin: connect to server at’localhost’ failed
- mysql problem solving: mysqladmin: connect to server at’localhost’ failed
- MySQL: if the remote connection using navicatip fails, prompt “is not allowed to connect to this MySQL server”
- The MySQL service suddenly hangs up with the error message can’t connect to MySQL server on ‘localhost’ (10061)
- Can’t connect to MySQL server error 111
- Sqlog connect to MySQL 8.0.24 remote server, error: 2058 solution
- Ntpdate reported an error when updating the clock, and the problem of no server suitable for synchronization found was solved
- Local can link to the server database, upload jar package to the server will report an error
- CentOS Liunx 7 uses rdesktop to remotely connect to the Alibaba Cloud server and it appears Failed to connect, CredSSP required by server.
- Mongodb uses Mongo to report error: could’t connect to server 127.0.0.1:27017, connection attempt failed: socket
- ERROR 2002 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)
- Can’t connect to MySQL server on ‘192.168.64.132‘
- Host is not allowed to connect to this MySQL server
- Error 2003 (HY000): can’t connect to MySQL server on ‘localhost’ (10061)
- Cannot connect to MySQL server on “host” (113)
- 2003 – Can‘t connect to MySQL server on ‘192.168.163.128‘(Unknown error )