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 use VirtualBox to build a local virtual machine environment on Mac

1. Big Data and Hadoop To study and learn about b...

Example of Vue uploading files using formData format type

In Vue, we generally have front-end and back-end ...

How to get the intersection/difference/union of two sets in mysql

Common scenarios of MySQL: getting the intersecti...

How to create users and manage permissions in MySQL

1. How to create a user and password 1. Enter the...

Vue directives v-html and v-text

Table of contents 1. v-text text rendering instru...

TortoiseSvn Little Turtle Installation Latest Detailed Graphics Tutorial

There were always problems when installing tortoi...

Div css naming standards css class naming rules (in line with SEO standards)

There are many tasks to be done in search engine o...

calc() to achieve full screen background fixed width content

Over the past few years, there has been a trend i...

Vue implements the countdown component for second kills

This article shares the specific code of Vue to i...

Introduction to the use and advantages and disadvantages of MySQL triggers

Table of contents Preface 1. Trigger Overview 2. ...