I have setup mysql (mariadb) on linux machiche. I have created a user 'newuser' like:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
when i do :
select user,password from user;
i can see:
+--------------+-------------------------------------------+
| user | password |
+--------------+-------------------------------------------+
| root | *password |
| newuser | *password |
+--------------+-------------------------------------------+
and when i execute this command :
select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
I am trying to connect to my database using java but i am getting below exception:
java.sql.SQLException: Cannot create connection:Access denied for user 'newuser'@'localhost' (using password: YES)
+------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for newuser@localhost |
+------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' IDENTIFIED BY PASSWORD '*7ABDF971526E9441B919C9FE77D50DB0363B3509' WITH GRANT OPTION |
+------------------------------------------------------------------------------------------------------------------------------------------------+
Java code to connect to db:
try {
Class.forName("com.mysql.jdbc.Driver");
// Connection connection = DriverManager.getConnection(connectionString);
Connection connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/iot?autoReconnect=true","newuser","password");
System.out.println("Connected --->" + connection);
return connection;
} catch (SQLException e) {
throw new SQLException("Cannot create connection:" + e.getMessage());
}
Can anyone help me what i am missing?