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)
檢視資料庫使用者
查詢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地址或主機名。+-----------------------+----------------+
| 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.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2137045/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysqldump: Got error: 2002: Can't connect to local MySQL server through.....MySqlGoErrorServer
- linux下連線mysql報錯ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysqLinuxMySqlErrorServer
- MySQL連線提示Can't connect to local MySQL server through socketMySqlServer
- Can't connect to local MySQL server through socket '/tmp/mysql.sock'MySqlServer
- MySQL 5.5 關閉資料庫報錯"Can't connect to local MySQL server through socket"MySql資料庫Server
- ERROR 2002(HY000):Can't connect to local MySQL socket '/tmp/mysql.sock'ErrorMySql
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock錯誤MySqlServer
- mysql 啟動報錯Can't connect to local MySQL server through socket '/data/mysql/mysql/mysql.sock'(111)MySqlServer
- ERROR 2002 (HY000): Cant connect to local MySQL server through socket的解決方法ErrorMySqlServer
- 解決Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) "MySqlServer
- ERROR 2002 (HY000): Can't connect server socket /tmp/mysql.sockErrorServerMySql
- 更換mysql資料目錄後出現ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 的解決辦法MySqlErrorServer
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)解決方法MySqlServer
- ERROR 2003 (HY000)Can't connect to MySQL server on '192.168.8.247' (113)ErrorMySqlServer
- ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)ErrorMySqlServerlocalhost
- ERROR 2002 (HY000): Can't connect server socket /var/run/mysqld/mysqld.sockErrorServerMySql
- MySQL 5.5 原始碼安裝報錯"[ERROR] Can't start server"MySql原始碼ErrorServer
- 連線MySQL錯誤:Can't connect to MySQL server (10060)MySqlServer
- Mysql報錯Fatal error:Can't open and lock privilege tablesMySqlError
- mysql can't connect error about privilege----not root userMySqlError
- MySQL5.6:mysql_secure_installation 報錯ERROR 2002 (HY000)MySqlError
- 異常:Can't connect to MySQL server (10060)MySqlServer
- MySQL 2003 - Can’t connect to MySQL server on (10060)MySqlServer
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- 【MySQL】ERROR 1005 (HY000): Can't create table' (errno: 150)MySqlError
- MySQL 5.7向表匯入資料包錯"ERROR 13 (HY000): Can't get stat of"MySqlError
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- MYSQL ERROR 2003 (HY000) CanMySqlError
- [ERROR] Can't open the mysql.plugin tableErrorMySqlPlugin
- MySQL問題記錄--Can't connect to MySQL server on localhost (10061)解決方法MySqlServerlocalhost
- Can't Connect to MySQL Server on IP Address (10061) 錯誤的解決方案MySqlServer
- MySQL "ERROR 1010(HY000):Error dropping database(canMySqlErrorDatabase
- mysql [ERROR] Can't create IP socket: Permission deniedMySqlError
- Navicat 連線 MySQL 失敗:2002-can‘t connect to server on localhost(10061)問題解決MySqlServerlocalhost
- Xtrabackup備份報錯Failed to connect to MySQL serverAIMySqlServer
- 【linux】Can't connect to MySQL server on 'XXX' (13)問題解決方式LinuxMySqlServer
- MySQL遠端連線ERROR 2003 (HY000) Cant connect to MySQL server on (10060)MySqlErrorServer
- Navicat連線centos裡mysql報錯Host is not allowed to connect to this MySQL serverCentOSMySqlServer