How to solve the abnormal error ERROR: 2002 in mysql

How to solve the abnormal error ERROR: 2002 in mysql

Recently, an error occurred while 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. First check /etc/rc.d/init.d/mysqld status to see if mysql has been started.

Also check if it's a permissions issue.

2. Make sure your mysql.sock is in that location.

mysql -u yourmysqlusername -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: [ OK ]
[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 the access permission problem of /var/lib/mysql.

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 and 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

I still found that the same thing happened. I ran /etc/init.d/mysql start and got an error: Starting MySQL Couldn't find MySQL manager or server. The mysqld service was not started. I ran /usr/local/mysql/bin/mysqld_safe &

Problem solved.

Summarize

Well, that’s all for this article. I hope that the content of this article can be helpful to your study or use of MySQL. If you have any questions, please leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Summary of handling JDBC connection mysql garbled code exception problem
  • Solution to 1449 and 1045 exceptions when connecting to MySQL
  • SELinux causes PHP to connect to MySQL abnormally. Solution to Can't connect to MySQL server
  • Sharing of experience on repairing MySQL innodb exceptions
  • MySQL definition and exception handling details
  • Analysis of exception handling in mysql stored procedures
  • MySQL database connection exception summary (worth collecting)

<<:  Detailed explanation of the implementation of WeChat applet track playback and the pitfalls encountered

>>:  Best tools for taking screenshots and editing them in Linux

Blog    

Recommend

The top fixed div can be set to a semi-transparent effect

Copy code The code is as follows: <!DOCTYPE ht...

Detailed tutorial on installing Ubuntu 19.10 on Raspberry Pi 4

Because some dependencies of opencv could not be ...

How to calculate the value of ken_len in MySQL query plan

The meaning of key_len In MySQL, you can use expl...

Solve the problem of inconsistency between mysql time and system time in docker

Recently, when I installed MySQL in Docker, I fou...

Nginx reverse proxy to go-fastdfs case explanation

background go-fastdfs is a distributed file syste...

Zabbix monitors Linux hosts based on snmp

Preface: The Linux host is relatively easy to han...

CSS3 creates 3D cube loading effects

Brief Description This is a CSS3 cool 3D cube pre...

Summary of the differences between MySQL storage engines MyISAM and InnoDB

1. Changes in MySQL's default storage engine ...

Detailed steps to modify MySQL stored procedures

Preface In actual development, business requireme...

Data URI and MHTML complete solution for all browsers

Data URI Data URI is a scheme defined by RFC 2397...

A brief analysis of how to use border and display attributes in CSS

Introduction to border properties border property...

Detailed explanation of the usage of the alias command under Linux

1. Use of alias The alias command is used to set ...

How to implement Linux automatic shutdown when the battery is low

Preface The electricity in my residence has been ...

JavaScript to achieve mouse drag effect

This article shares the specific code of JavaScri...