Mysql连接报错:java.sql.SQLException:null,message from server:"Host '27,45,38,132' is not allowed to connect.
原因是:远程服务器不允许你的java程序访问它的数据库。所以,我们要对远程服务器进行设置,使它允许你进行连接。
工具sqldeveloper连接远程的MySQL 数据库时,配置连接信息,连接发生错误,提示:message from server: "Host '192.168.1.8' is not allowed to connect to this MySQL server
但是将IP地址改为localhost又能正常连接到MySQL数据库。
临时处理方案:
1、先用localhost方式连接到MySQL数据库,然后使用MySQL自带的数据库mysql;# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 971
Server version: 5.5.56-log Source distribution
Copyright (c) 2000, 2017, 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> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
2、执行:select host from user where user = 'root'; 发现,host的值就是localhost。
所以将它的值改掉:update user set host='%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 不予理会
3、修改完成后,执行:flush privileges;
将修改内容生效,再次配置时,用IP地址或者localhost 就都能正常连接到MySQL数据库了。
原文:http://blog.51cto.com/meiling/2155927