soulhi salah
soulhi salah

Reputation: 409

Mysql Access denied for user 'user'@'localhost' (using password: yes) "openshift"

i want to connect to mysql database hosted in openshift server using java. everything works fine on my local computer but when i try connect to openshift database i am getting this error

java.sql.SQLException: Access denied for user : 'userEl'@'@localhost' (using password: yes) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:795) at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:44) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at myjava.Test.main(Test.java:13)

here is my code

    public class Test {

        public static void main(String[] args) {
            String state;
            try {
                Connection con = DriverManager.getConnection("jdbc:mysql://ip/mydb","userEl","password");
                Statement stm= con.createStatement();
                ResultSet rs= stm.executeQuery("SELECT * FROM server");

                  while(rs.next()){
                      state=rs.getString(1);
                      System.out.println("state = "+ state);
                  }
                        } catch (SQLException e) {
                        e.printStackTrace();
                                }
                }

Upvotes: 0

Views: 1254

Answers (1)

user2879327
user2879327

Reputation:

When using the OpenShift Online MySQL cartridge, you can not login as "root" or as a 'user'@'localhost'. You must login with the credentials that are provided to you by OpenShift when installing the MySQL cartridge. You can view the credentials by sshing into your gear and running the command env | grep MYSQL, or you can view them in the OpenShift Online Web Console. For more information about using MySQL on OpenShift Online, please refer to this document (https://developers.openshift.com/databases/mysql.html) in the Developer Portal.

Upvotes: 0

Related Questions