问题描述:连接mysql数据库时报错ERROR 1130,如下所示:
数据库:mysql 5.5.18
1、异常重现
[leo@liujun ~]$ mysql -umisuser -pmisuser -h192.168.11.21 -Dmisdb
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host '192.168.133.21' is not allowed to connect to this MySQL server
2、原因分析
被连接的数据库不允许使用主机192.168.133.21访问.
3、解决方法
--在服务器端(192.168.11.21)授予权限.
[mysql@tmisdb01 ~]$ mysql -uroot -S /mysql/data/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2599
Server version: 5.5.18-rel23.0-log Percona Server with XtraDB (GPL), Release rel23.0, Revision 203
Copyright (c) 2000, 2011, 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> select user,host from mysql.user;
+---------+--------------+
| user | host |
+---------+--------------+
| misdb | 192.168.133.%|
| admin | 192.168.136.%|
| repl | 192.168.136.%|
| misuser | 192.168.180.%|
| root | 127.0.0.1 |
| root | localhost |
+---------+--------------+
9 rows in set (0.03 sec)
--授权
mysql> GRANT ALL PRIVILEGES ON *.* TO 'misuser'@'192.168.133.21' IDENTIFIED BY 'misuser' WITH GRANT OPTION;
Query OK, 0 rows affected (0.04 sec)
mysql> select user,host from mysql.user;
+---------+--------------+
| user | host |
+---------+--------------+
| misdb | 192.168.133.%|
| admin | 192.168.136.%|
| repl | 192.168.136.%|
| misuser | 192.168.133.21|
| misuser | 192.168.180.%|
| root | 127.0.0.1 |
| root | localhost |
+---------+--------------+
10 rows in set (0.00 sec)
4、连接验证
[leo@liujun ~]$ mysql -umisuser -pmisuser -h192.168.11.21 -Dmisdb
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2602
Server version: 5.5.18-rel23.0-log Percona Server with XtraDB (GPL), Release rel23.0, Revision 203
Copyright (c) 2009-2018 Percona LLC and/or its affiliates
Copyright (c) 2000, 2018, 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>
参考文档:https://blog.csdn.net/nayun123/article/details/117128159