21:19:11.422 [main] ERROR com.lancoo.ecbdc.persist.mysql.MySQL - null, message from server: "Host 'master' is not allowed to connect to this MySQL server"
21:19:11.424 [main] ERROR com.lancoo.ecbdc.persist.mysql.MySQL - java.sql.SQLException: null, message from server: "Host 'master' is not allowed to connect to this MySQL server"
java.sql.SQLException: null, message from server: "Host 'master' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1111)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2494)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2527)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2309)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:419)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.lancoo.ecbdc.persist.mysql.MySQL.getConnection(MySQL.java:37)
at com.lancoo.ecbdc.persist.mysql.MySQL.<init>(MySQL.java:31)
at com.lancoo.ecbdc.persist.DBFactory.getPersist(DBFactory.java:12)
at com.lancoo.ecbdc.persist.App.main(App.java:15)
Exception in thread "main" java.lang.NullPointerException
at com.lancoo.ecbdc.persist.mysql.MySQL.query(MySQL.java:53)
at com.lancoo.ecbdc.persist.App.main(App.java:17)
mysql> select host from mysql.user where user='root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.01 sec)
默认情况下,root仅仅允许从localhost和127.0.0.1登录到MySQL
解决方法:
使用以下命令授权
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '<root-password>' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> select host from mysql.user where user='root';
+-----------+
| host |
+-----------+
| % |
| localhost |
+-----------+
2 rows in set (0.00 sec)