Home >Database >Mysql Tutorial >Solution sharing for exception error ERROR: 2002 in mysql
Recently, when I started mysql, I found that mysql reported an error. The error code was 2002. By searching for relevant information, I found that it was an access permission issue with var/lib/mysql, so this article mainly introduces mysql. Friends in need can refer to the solution for the abnormal error ERROR: 2002. Let’s take a look below.
Recently, an error was reported when starting mysql. The error message is as follows:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock' (2)
Troubleshooting process
1. Check first /etc/rc.d/init.d/mysqld status
Check if mysql has been started.
Also check if there is a permission problem.
2 , Make sure your mysql.sock is in that location,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock
3. Try: service mysqld start
4. If it is a permission problem, change it first Permissions #chown -R mysql:mysql /var/lib/mysql
[root@localhost ~]# /etc/init.d/mysqld start 启动 MySQL: [ 确定 ] [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 that the access permissions of /var/lib/mysql are problematic.
shell> chown -R mysql:mysql /var/lib/mysql
Then start the server
shell> /etc/init.d/mysql start
After the server starts normally, check /var/lib/mysql to automatically generate the mysql.sock file.
But my problem is still not solved.
The problem is finally solved:
Method: Modify /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
If the problem is still the same, run /etc/init.d/mysql start
Error: Starting MySQLCouldn't find MySQL manager or server because the mysqld service is not started, run/usr/local/mysql/bin/mysqld_safe &
problem solved.
Summarize
The above is the detailed content of Solution sharing for exception error ERROR: 2002 in mysql. For more information, please follow other related articles on the PHP Chinese website!