docker mysql "ERROR 2002 (HY000): Can't connect to local MySQL server through socket", "mysql container keeps restarting" processing method
wrong description
-
1. Error phenomenon 1
The mysql container keeps restarting , as shown in the figure below: -
2. Error phenomenon 2
After entering the mysql container, execute the command:mysql -uroot -p
Error message:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
operating environment
- Docker version 20.10.2, build 2291f61
- ubuntu 16.04 LTS
- mysql 5.6.39
error analysis
Execute docker logs mysql first to view the log
and enter the following command to view the log information:
docker logs mysql
You can see the following error message:
2022-09-29 06:43:20 1 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
2022-09-29 06:43:20 1 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2022-09-29 06:43:20 1 [Note] InnoDB: Unable to open the first data file
2022-09-29 06:43:20 7f4bf44f9740 InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html
2022-09-29 06:43:20 1 [ERROR] InnoDB: Can't open './ibdata1'
2022-09-29 06:43:20 1 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2022-09-29 06:43:20 1 [ERROR] Plugin 'InnoDB' init function returned error.
2022-09-29 06:43:20 1 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2022-09-29 06:43:20 1 [ERROR] Unknown/unsupported storage engine: InnoDB
2022-09-29 06:43:20 1 [ERROR] Aborting
There are 2 important error messages here:
Error message 1:
2022-09-29 06:43:20 1 [ERROR] InnoDB: Can't open './ibdata1'
Error message 2:
2022-09-29 06:43:20 1 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
Solution
1. Use online processing methods
-
1. Try method 1
from the error message:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysqldata/mysql.sock' (111)
To determine whether it may be a configuration error in /etc/my.cnf
Determine whether the path of mysql.sock in my.cnf is consistent with the path of the error message. If not, refer to the following article to solve it:
https://www.jb51 .net/article/56952.htm
http://t.zoukankan.com/magmell-p-8384525.htmlThe mysql.sock path of my my.cnf is consistent with the path of the error message, so it is not caused by this problem.
-
2. Try method 2
to execute the command:service mysqld status
Prompt information:
mysqld is stopped
Trying to start the mysql service
service mysqld start
Prompt error:
mysqld: unrecognized service
Determine whether mysql is installed
Refer to this solution for the installation method:
https://blog.csdn.net/u012979864/article/details/79626427I installed mysql, not this mistake.
-
3. Try method 3.
If mysql starts normally, refer to this article for solution:
https://blog.csdn.net/qq_30938705/article/details/87166459My mysql obviously does not start normally, and the mysql container keeps restarting, not this problem.
2. My handling method
-
Error Analysis:
From the error message:[ERROR] InnoDB: Can't open './ibdata1'
To judge, it has something to do with ibdata1. Because the docker process has been interrupted abnormally, I suspect that ibdata1 cannot be opened due to file corruption. So take the following steps to solve the problem:
-
2.1 Access to the container
docker exec -it mysql bash
-
2.2 Delete ib_logfile0 ib_logfile1 ibdata1
first find the file locationfind / -name ib_logfile0
My file path:
/var/lib/mysql
Delete files ib_logfile0 ib_logfile1 ibdata1:
rm ib_logfile0 ib_logfile1 ibdata1
-
2.3 Restart the mysql container,
first exit the mysql containerexit
Restart the mysql container
docker restart mysql
-
2.4 Test mysql
into the container:docker exec -it mysql bash
Execute the command (enter mysql as the root account, which can be modified as needed):
mysql -u root -p
After entering the password, the following information is obtained:
root@xxx:/# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.39 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
If the above information appears, it means that mysql starts normally.
At this point, my problem is solved.
reference
1.http://t.zoukankan.com/magmell-p-8384525.html
2.https://blog.csdn.net/qq_37844454/article/details/122834493
3.https://www.jb51.net/article/56952.htm
4.https://blog.csdn.net/u012979864/article/details/79626427