ERROR 2002 (HY000): Can ' t connect to the local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)
Workaround:
1 The default Mysql.sock file is in the/tmp directory.
2 We establish a soft connection, ln-s/tmp/mysql.sock/var/lib/mysql/mysql.sock
Problem 2:timeout error occurred trying to start MySQL Daemon.
#/etc/init.d/mysqld restart
stopping MySQL [OK]
Timeout error occurred trying to start MySQL Daemon. [Failure]
But this time MySQL actually started, because with the NETSTAT-LN command to see 3306 Port has started. You can also connect to a database using mysql-u root-p password.
Workaround:
Modify/etc/init.d/mysqld.
Create Dameon users in MySQL, and then modify/etc/init.d/mysqld.
The specific actions are as follows:
Let's take a look at how the/etc/init.d/mysqld start script works, and note the following
# If You ' ve removed anonymous users, this line must is changed to
# Use a user ' is allowed to ping mysqld.
ping= "/usr/bin/mysqladmin-uunknown_mysql_user Ping"
# Spin for a maximum of ten seconds waiting for the ' server to ' come up
If [$ret-eq 0]; Then
For x in 1 2 3 4 5 6 7 8 9 10; Todo
If [-N "' $ping 2>/program/null '"]; Then
Break
Else
Sleep 1;
Fi
Done
if! ([-N "' $ping 2>/program/null ']); Then
echo "Timeout error occurred trying to start MySQL
Daemon. " Action $ "Starting $prog:"/bin/false
Else
Action $ "Starting $prog:"/bin/true
Fi
Else
Action $ "Starting $prog:"/bin/false
Fi
[$ret-eq 0] && touch/var/lock/subsys/mysqld
Return $ret
We see that the script determines whether MySQL is starting, using the Mysqladmin ping command.
And this command needs to be able to log in to MySQL if it is to execute correctly. Some default accounts are now deleted, and other accounts have been set up with passwords (passwords are not set by default). So it has no way to connect to MySQL.
So I used the following method to solve.
A) Establish an account number without setting a password and giving no permissions.
b) Modification of/ETC/INIT.D/MYSQLD
I'll give you the details below.
#mysql-U root-p passwd
mysql>grant Select on test.* to Daemon@localhost
Mysql>revoke Select on test.* from Daemon@localhost
VI Open/ETC/INIT.D/MYSQLD
put this down.
ping= "/usr/bin/mysqladmin-uunknown_mysql_user Ping"
Amended to
ping= "/usr/bin/mysqladmin-udaemon Ping"
Save, exit.
Re-starting MySQL
#/etc/init.d/mysqld restart
stopping MySQL: [OK]
Starting MySQL: [OK]
That's it.