Analysis and Solution of ERROR:2002 Reported When MySQL Starts

Analysis and Solution of ERROR:2002 Reported When MySQL Starts

Preface

This article mainly introduces the analysis and solution of MySQL startup error: 2002. It is shared for your reference and study. Let’s take a look at the detailed introduction.

1. Fault phenomenon

[root@localhost scripts]# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2)

2. Fault analysis

View the status of the MySQL instance

[root@localhost scripts]# netstat -ntlp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 13001/mysqld

View my.cnf configuration about socket

[root@localhost scripts]# more /etc/my.cnf |grep sock
socket = /tmp/mysqld.sock

This means that mysqld has claimed the correct sock file, but the client connection still looks for the sock file in the initial directory.

Next, check the background log. There is an ERROR about the full query log. This is an error caused by the directory not existing and has nothing to do with the current fault.

[root@localhost scripts]# more SZDB.err
  ............
2014-10-11 13:17:21 13001 [Note] InnoDB: 5.6.12 started; log sequence number 1625997
/app/soft/mysql/bin/mysqld: File '/log/mysql_logs/slowquery.log' not found (Errcode: 2 - No such file or directory)
2014-10-11 13:17:21 13001 [ERROR] Could not use /log/mysql_logs/slowquery.log for logging (error 2). Turning logging off for the who
le duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
2014-10-11 13:17:21 13001 [Note] Server hostname (bind-address): '*'; port: 3306
2014-10-11 13:17:21 13001 [Note] IPv6 is available.
2014-10-11 13:17:21 13001 [Note] - '::' resolves to '::';
2014-10-11 13:17:21 13001 [Note] Server socket created on IP: '::'.
2014-10-11 13:17:21 13001 [Note] Event Scheduler: Loaded 0 events
2014-10-11 13:17:21 13001 [Note] /app/soft/mysql/bin/mysqld: ready for connections.
Version: '5.6.12-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution
#Author :Leshami
#Blog: http://www.linuxidc.com

3. Troubleshooting

a. Solve by configuring the my.cnf mysql option socket file location

Stop the mysql server first

[root@localhost scripts]# systemvtl restart mysqld
Shutting down MySQL. [ OK ]

Modify my.cnf as follows

[root@localhost scripts]# vi /etc/my.cnf
[mysql]
no-auto-rehash
socket = /tmp/mysqld.sock #Add this line

Restart mysql server

[root@localhost scripts]# systemctl restart mysqld 
Starting MySQL..[ OK ]

Connect again normally

[root@localhost scripts]# mysql -uroot -p
Enter password:
mysql> show variables like 'version';
+---------------+------------+
| Variable_name | Value |
+---------------+------------+
| version | 5.6.12-log |
+---------------+------------+

b. Establish a link method for the socket file

[root@SZDB mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
ln: creating symbolic link `/data/mysqldata/mysql.sock' to `/tmp/mysql.sock': File exists
[root@SZDB mysqldata]# rm mysql.sock #The above prompt says that the file exists, so delete the previous mysql.sock file [root@SZDB mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
[root@SZDB mysqldata]# ls -hltr mysql.sock
lrwxrwxrwx 1 root root 15 Oct 11 14:00 mysql.sock -> /tmp/mysql.sock
[root@SZDB mysqldata]# mysql -uroot -p
Enter password:
mysql> show variables like 'socket';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| socket | /tmp/mysql.sock |
+---------------+-----------------+

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the problem that the InnoDB engine is disabled when MySQL is started
  • How to solve "Unable to start mysql service error 1069"
  • Solution to the problem that the configuration file my.cnf in MySQL cannot be started due to permission issues
  • How to solve the problem that MySQL cannot start because it cannot create PID
  • Detailed explanation of Mysql 5.7.18 installation method and the process of starting MySQL service
  • Solve the problem that the service cannot be started when installing the decompressed version of mysql 5.7.18 winx64 on Win7 x64
  • Solution to MySQL failure to start

<<:  How to change $ to # in Linux

>>:  Detailed explanation of CocosCreator project structure mechanism

Recommend

How to find slow SQL statements in MySQL

How to find slow SQL statements in MySQL? This ma...

Tutorial on configuring and using i3 window manager in Linux

In this article, I will show you how to install a...

Briefly describe mysql monitoring group replication

Original text: https://dev.mysql.com/doc/refman/8...

Native JS to achieve special effects message box

This article shares with you a special effect mes...

Mac installation mysqlclient process analysis

Try installing via pip in a virtual environment: ...

Detailed explanation of the steps to create a web server with node.js

Preface It is very simple to create a server in n...

Introduction to Common XHTML Tags

<br />For some time, I found that many peopl...

10 Underused or Misunderstood HTML Tags

Here are 10 HTML tags that are underused or misun...

How to monitor Tomcat using LambdaProbe

Introduction: Lambda Probe (formerly known as Tom...

Bootstrap 3.0 learning notes button style

This article mainly explains the style of buttons...

MySQL 8.0.16 installation and configuration tutorial under Windows 10

This article shares with you the graphic tutorial...

Summarize several common ranking problems in MySQL

Preface: In some application scenarios, we often ...

Complete steps to use samba to share folders in CentOS 7

Preface Samba is a free software that implements ...

Summary of the differences between count(*), count(1) and count(col) in MySQL

Preface The count function is used to count the r...