0

I trying to set "ALL PRIVILEGES" from Java on remote MySQL database test and user test . Here is snippet of my code:

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';");

Nothing extraordinary. All queries from root user work fine, but in this partucular case I'm getting error:

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

What did I do wrong?

UPDATE

Here's answer. So, the problem wasn't solved ...

2
  • How come the user name reads 'root'@'%'? Commented Apr 24, 2016 at 17:10
  • Please include the stacktrace of the exception. Commented Apr 25, 2016 at 7:51

3 Answers 3

0

Try establishing connection with

DriverManager.getConnection("jdbc:mysql://hostname:port/dbname","username", "password");
Sign up to request clarification or add additional context in comments.

Comments

0

Please make sure that 'root@yourHost' (especially from yourHost) indentified by 'pswrd' has rights to manage privileges on this database.

Comments

0

try adding host like this 'test'@'yourhost'

1 Comment

A little explanation would improve the quality of your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.