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

Recommend

Detailed tutorial on installing harbor private warehouse using docker compose

Overview What is harbor? The English word means: ...

Summary of 16 XHTML1.0 and HTML Compatibility Guidelines

1. Avoid declaring the page as XML type . The pag...

MySQL triggers: creating and using triggers

This article uses examples to describe the creati...

Summary of various uses of JSON.stringify

Preface Anyone who has used json should know that...

18 killer JavaScript one-liners

Preface JavaScript continues to grow and prosper ...

JavaScript color viewer

This article example shares the specific code of ...

In-depth analysis of MySQL indexes

Preface We know that index selection is the work ...

Solve the problem of docker pull image error

describe: Install VM under Windows 10, run Docker...

CSS implements the bottom tapbar function

Now many mobile phones have the function of switc...

Examples of implementing progress bars and order progress bars using CSS

The preparation for the final exams in the past h...

Let's talk about bitwise operations in React source code in detail

Table of contents Preface Several common bit oper...

How to add website icon?

The first step is to prepare an icon making softwa...

Solution to the welcome to emergency mode message when booting CentOS7.4

Today I used a virtual machine to do an experimen...

JavaScript imitates Jingdong magnifying glass special effects

This article shares the specific code of JavaScri...