Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of error reporting when connecting to mysql database

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the error report analysis of connecting to the mysql database, the content of the article is carefully selected and edited by the author, the connection mysql database error report analysis has a certain pertinence, the reference significance for everyone is still relatively great, the following with the author to understand the next topic content.

1. A binary installation of mysql 5.7has been installed today, and the following error was reported when connecting to mysql database:

[root@iccsdb01 mysql] # mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/ tmp/mysql.sock' (2)

2. According to the prompt, the sock file should not be there. By looking at the process configuration, we find the following

[root@iccsdb01 bin] # ps-ef | grep mysql

Root 9196 3125 0 11:18 pts/2 00:00:00 tail-f mysqld.log

Root 11404 10 14:13 pts/1 00:00:00 / bin/sh / home/mysql/sysinfo/mysql/bin/mysqld_safe-- datadir=/my_data/sysinfo-- pid-file=/my_data/sysinfo/iccsdb01.pid

Mysql 11616 11404 0 14:13 pts/1 00:00:00 / home/mysql/sysinfo/mysql/bin/mysqld-basedir=/home/mysql/sysinfo/mysql-datadir=/my_data/sysinfo-plugin-dir=/home/mysql/sysinfo/mysql/lib/plugin-user=mysql-log-error=/var/log/mysqld.log-pid-file=/my_data/sysinfo/iccsdb01.pid-socket=/var/lib/mysql/mysql.sock

From the above, we can see that the default mysql.sock of mysql is in / var/lib/mysql/mysql.sock.

But the Linux system always goes to / tmp/mysql.sock, so it will report an error.

Solution one

1. Create a connection file to the specified directory

Ln-s / var/lib/mysql/mysql.sock / tmp/mysql.sock

2. Test connection logged in successfully

[root@iccsdb01 /] # mysql-u root-p

Enter password:

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 5

Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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 >

Solution two

Modify the "/ etc/my.cnf" configuration file, add the "[client]" option and "[mysql]" option in the configuration file, and use the "socket" parameter value under these two options, which is exactly the same as the "socket" parameter value under the "[mysqld]" option, pointing to the socket file path. As follows:

[mysqld] datadir=/my_data/sysinfosocket=/var/lib/mysql/mysql.sock... Omit the n line. [client] default-character-set=utf8socket=/var/lib/mysql/mysql.sock [mysql] default-character-set=utf8socket=/var/lib/mysql/mysql.sock

After the modification, restart the mysqld service to solve this problem.

After reading the above error report analysis of connecting to mysql database, many readers must have some understanding. If you need more industry knowledge and information, you can continue to pay attention to our industry information column.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report