[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地址或主机名。+-----------------------+----------------+
| host | user |
+-----------------------+----------------+
| % | ADMGEMALTO |
| % | MGRGEMALTO |
| % | TECHADMGEMALTO |
| localhost | ADMGEMALTO |
| localhost | MGRGEMALTO |
| localhost | TECHADMGEMALTO |
| localhost | root |
| localhost.localdomain | root |
+-----------------------+----------------+
8 rows in set (0.00 sec)
解决方法:
查询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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。