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

MySQL error report & # 039 error error 2002 (HY000): Can't connect to local MySQL server through'

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

Share

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

Log in Database Save

[root@localhost Percona-Server-5.6.34-rel79.1-Linux.x86_64.ssl101]# bin/mysql -h localhost -P 3306 -uroot -p

Enter password:

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

View Database Users

mysql> select host, user from mysql.user;

+-----------------------+----------------+

| host | user |

+-----------------------+----------------+

| % | ADMGEMALTO |

| % | MGRGEMALTO |

| % | TECHADMGEMALTO |

| localhost | ADMGEMALTO |

| localhost | MGRGEMALTO |

| localhost | TECHADMGEMALTO |

| localhost | root |

| localhost.localdomain | root |

+-----------------------+----------------+

8 rows in set (0.00 sec)

Solution:

In MySQL, you need to use socket to connect to localhost; when you log in to the database with the-h option, it should be followed by an IP address or hostname.

Search socket

[root@localhost Percona-Server-5.6.34-rel79.1-Linux.x86_64.ssl101]# ps -ef|grep mysql

root 2940 2917 0 15:31 pts/0 00:00:00 /bin/sh bin/mysqld_safe --defaults-file=/u01/mysql_data/my.cnf

mysql 3837 2940 0 15:31 pts/0 00:00:07 /mysql5.6/Percona-Server-5.6.34-rel79.1-Linux.x86_64.ssl101/bin/mysqld --defaults-file=/u01/mysql_data/my.cnf --basedir=/database/percona --datadir=/u01/mysql_data --plugin-dir=/database/percona/lib/mysql/plugin --user=mysql --log-error=/u01/mysql_data/mysqld_error.log --open-files-limit=8192 --pid-file=/u01/mysql_data/localhost.localdomain.pid --socket=/u01/mysql_data/mysql.sock --port=3306

root 5346 2917 0 17:05 pts/0 00:00:00 grep mysql

Log in to the database using the-S connection socket

[root@localhost Percona-Server-5.6.34-rel79.1-Linux.x86_64.ssl101]# bin/mysql -S /u01/mysql_data/mysql.sock -uroot -p

Enter password:

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

Your MySQL connection id is 29

Server version: 5.6.34-79.1-log Percona Server (GPL), Release 79.1, Revision 1c589f9

Copyright (c) 2009-2016 Percona LLC and/or its affiliates

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

Connect to the database using-h followed by hostname

[root@localhost Percona-Server-5.6.34-rel79.1-Linux.x86_64.ssl101]# bin/mysql -h localhost.localdomain -P 3306 -uroot -p

Enter password:

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

Your MySQL connection id is 30

Server version: 5.6.34-79.1-log Percona Server (GPL), Release 79.1, Revision 1c589f9

Copyright (c) 2009-2016 Percona LLC and/or its affiliates

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

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