MySQL报错'ERROR 2002 (HY000): Can't connect to local MySQL server through'
发表于:2024-11-26 作者:千家信息网编辑
千家信息网最后更新 2024年11月26日,登陆数据库保存[root@localhost Percona-Server-5.6.34-rel79.1-Linux.x86_64.ssl101]# bin/mysql -h localhost -P
千家信息网最后更新 2024年11月26日MySQL报错'ERROR 2002 (HY000): Can't connect to local MySQL server through'登陆数据库保存
[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)
查看数据库用户
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)
解决方法:
在MySQL中,需要使用socket方式连接localhost;而当使用-h选项登陆数据库时,后面接的应该是IP地址或主机名。
查询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
使用-S连接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.
使用-h接主机名的方式连接到数据库
[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.
[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)
查看数据库用户
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)
解决方法:
在MySQL中,需要使用socket方式连接localhost;而当使用-h选项登陆数据库时,后面接的应该是IP地址或主机名。
查询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
使用-S连接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.
使用-h接主机名的方式连接到数据库
[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.
数据
数据库
方式
主机
登陆
地址
方法
用户
查询
登录
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
tot软件开发
部队网络安全 严禁
湖南正规软件开发公司
逃离塔科夫服务器芬兰是哪个
云计算中心和网络安全的关系
张家港技术软件开发报价方案
深圳有什么软件开发培训学校
添加服务器对wifi有无影响
上海专业网络技术批发价
网络安全和防盗
我国的计算机网络技术
中科大网络安全学院院长
英雄联盟山东有哪些服务器
纳克萨玛斯服务器有前景吗
山谷网络安全有限公司
高性能 数据库
绣绣网络技术北京有限公司
数据库语句怎么写百分比
windows数据库
网络安全宣传周农商行通讯稿
组态用服务器还是工控机
网络安全法二十七条解读
域控制服务器集中管理网络
中国银行 软件开发 待遇
添加服务器对wifi有无影响
正确认识网络安全作文
为什么要做数据库开发
墨博云舟用的服务器是什么牌子
山东办公系统软件开发靠谱吗
藏宝阁交易后原服务器