MySQL

MySQL连接错误解决方法

2019-04-15  本文已影响0人  HYIndex

软件环境

故障一

只能通过localhost登录MySQL

  1. 报错如下

$mysql -h172.16.0.1 -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host '172.16.0.1' is not allowed to connect to this MySQL server

  1. 解决方法
    此处参考自:https://stackoverflow.com/questions/19101243/error-1130-hy000-host-is-not-allowed-to-connect-to-this-mysql-server

mysql>SELECT host FROM mysql.user WHERE User = 'root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.24 sec)
一般结果中只有localhost或同时有localhost和127.0.0.1;

CREATE USER 'root'@'ip_address' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'ip_address';

CREATE USER 'root'@'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

FLUSH PRIVILEGES;

故障二

  1. 报错如下

$mysql -h172.16.0.1 -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '172.16.0.1' (111)

  1. 解决方法

$vim /etc/mysql/mysql.conf.d/mysqld.cnf

注释
#bind-address = 127.0.0.1
修改
bind-address = 0.0.0.0

$service mysql restart

再次尝试登录即可成功登录!

上一篇下一篇

猜你喜欢

热点阅读