Connecting to MySql using Java SSL connection
I am trying to connect to a MySql database which is using an ssl connection with java and has problems, if someone can help me it would be very helpful.
Manual connection to MySql:
We are using MySQL Workbench, parameters - hostname - "test-db1-ro-xxxxxx.net", port - 3306, username, password. There is an SSL CA file - mysql-ssl-ca-cert.pem, manual connection succeeded.
I tried the same in java (on windows system) My code:
String url = "jdbc:mysql://test-db1-ro.apdev.XXXXXX.net:3306/database";
String driver = "com.mysql.jdbc.Driver";
String userName = "XXXXXXXX";
String password = "XXXXXXXX";
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url,userName,password);
when i run the code i get access denied error i think it has to do with SSL connection.
I can't seem to figure out how to use the .pem file to create a secure database connection in this case.
Can anyone help, did different things but always got the same access as the error.
Full StackTrace:
java.sql.SQLException: Access denied for user 'xxxxxxxx' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at TestDBConnection.main(TestDBConnection.java:34)
source to share
You are having authentication problems.
On MySql terminal:
GRANT ALL ON *.* TO 'user'@'%' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
If the problem still persists:
GRANT ALL ON *.* TO 'user'@'%' WITH GRANT OPTION;
This command grants superuser privileges.
FLUSH PRIVILEGES;
To make sure your privileges are loaded.
NB: Do not use this account on publicly accessible websites.
source to share