繁体   English   中英

在executeUpdate Java MySQL中出错

[英]Getting error in executeUpdate Java MySQL

我试图在远程MySQL数据库test和用户test上从Java设置“所有特权”。 这是我的代码的片段:

Class.forName("com.mysql.jdbc.Driver");
Connection con = null;
con = (Connection) DriverManager.getConnection("jdbc:mysql://xx.xxx.xxx.xx:3306/?user=root&password=pswrd");

Statement st = con.createStatement();
int res = st.executeUpdate("GRANT ALL PRIVILEGES ON test.* TO 'test'@'%' IDENTIFIED BY '12345';");

没什么特别的。 来自root用户的所有查询都可以正常工作,但是在这种特殊情况下,我遇到了错误:

Exception in thread "main"   com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'root'@'%' to database 'test'

我做错了什么?

更新

这是答案 因此,问题没有得到解决...

尝试建立与

DriverManager.getConnection("jdbc:mysql://hostname:port/dbname","username", "password");

请确保由“ pswrd”标识的“ root @ yourHost”(尤其是来自yourHost)具有管理此数据库特权的权限。

尝试添加主机,例如“ test” @“ yourhost

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM