Solution of Exception Error ERROR: 2002 in mysql
- 2021-07-10 21:01:16
- OfStack
Recently, an error was reported when starting mysql, and the error prompt is as follows:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket ' /var/lib/mysql/mysql.sock' (2)
Checking process
1. Check first
/etc/rc.d/init.d/mysqld status
See if mysql has started.
In addition, see if it is a permission problem.
2. Determine if your mysql. sock is in that position,
mysql -u Yours mysql User name -p -S /var/lib/mysql/mysql.sock
3. Try:
service mysqld start
4. If it is a permission problem, change the permission first
#chown -R mysql:mysql /var/lib/mysql
[root@localhost ~]# /etc/init.d/mysqld start
Start MySQL : [ Determine ]
[root@localhost ~]# mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
The reason is,/var/lib/mysql access issues.
shell> chown -R mysql:mysql /var/lib/mysql
Then start the server
shell> /etc/init.d/mysql start
View/var/lib/mysql will automatically generate the mysql. sock file after the server starts normally.
But my problem is still unsolved.
The problem is finally solved:
Method: Modification/etc/my. conf:
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/usr/local/mysql
If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:
[client]
socket=/var/lib/mysql/mysql.sock
Discover that it is still the same, run
/etc/init.d/mysql start
Error: Starting MySQLCouldn 't find MySQL manager or server is mysqld service not started, running
/usr/local/mysql/bin/mysqld_safe &
Problem solving.
Summarize