无法连接mysql数据库错误总结_无法连接MySQL数据库错误总结

1、可能密码不对

[root@slave162 mysql3311]# mysql -uroot -P3311 -h192.168.60.162 -p123

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1045 (28000): Access denied for user 'root'@'slave162.netposa' (using password: YES)错误原因:可能是用户名或密码不对,或者权限不够

解决方法:检查用户名和密码以及权限,然后再连接

2、本地连接,密码权限都对,但是无法连接

[root@slave162 mysql3311]# mysql -uroot -P3311 -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)错误原因:数据库本地连接默认使用的是/tmp/mysql.sock去连接数据库的,如果数据库的sock文件不是/tmp/mysql.sock,客户端找不到这个文件就报错

解决方法:找到数据库用的sock文件,然后使用-S参数让客户端使用这个文件,或者是在my.cnf中的[client]下面添加socket配置使其和实际的一样

[root@slave162 mysql3311]# ps -ef|grep mysqld

root 21096 1 0 11:10 pts/1 00:00:00 /bin/sh /usr/local/mysql3311/bin/mysqld_safe --datadir=/usr/local/mysql3311/data --pid-file=/usr/local/mysql3311/data/slave162.netposa.pid

mysql 21353 21096 0 11:10 pts/1 00:00:00 /usr/local/mysql3311/bin/mysqld --basedir=/usr/local/mysql3311 --datadir=/usr/local/mysql3311/data --plugin-dir=/usr/local/mysql3311/lib/plugin --user=mysql --log-error=/usr/local/mysql3311/data/slave162.netposa.err --pid-file=/usr/local/mysql3311/data/slave162.netposa.pid --socket=/tmp/mysql3311.sock --port=3311

root 21658 16517 0 11:25 pts/1 00:00:00 grep mysqld

[root@slave162 mysql3311]#

[root@slave162 mysql3311]# mysql -uroot -p123456 -S /tmp/mysql3311.sock

mysql: [Warning] Using a password on the command line interface can be insecure.

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

Your MySQL connection id is 8

Server version: 5.7.14-log MySQL Community Server (GPL)

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.

mysql>

mysql>

或者修改 /etc/my.cnf,在[client]下添加socket=/tmp/mysql3311.sock

[root@slave162 mysql3311]# vim /etc/my.cnf

[root@slave162 mysql3311]#

[root@slave162 mysql3311]#

[root@slave162 mysql3311]#

[root@slave162 mysql3311]# mysql -uroot -P3311 -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

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

Your MySQL connection id is 11

Server version: 5.7.14-log MySQL Community Server (GPL)

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.

mysql>

mysql>

3、防火墙可能导致下面错误

[root@poseidon01 ~]# mysql -uroot -P3311 -h192.168.60.162 -p123456

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.60.162' (113)

错误原因:远程连接的时候,可能会因为防火墙,导致无法连接数据库。

解决方法:要么配置防火墙,要么关闭防火墙。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值