用户'用户'@'localhost'拒绝Mysql访问(使用密码:是)“openshift”

时间:2016-04-10 21:00:19

标签: java mysql openshift

我想使用java连接到mysql服务器中托管的openshift数据库。 一切正常在我的本地计算机上工作,但当我尝试连接到openshift数据库时,我得到这个error

  

java.sql.SQLException:拒绝用户访问:'userEl'@'@ localhost'(使用密码:是)               在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)               在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)               在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)               在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)               在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)               在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)               在com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)               在com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)               在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)               在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:795)               在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)               在com.mysql.jdbc.Util.handleNewInstance(Util.java:404)               在com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)               在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)               at java.sql.DriverManager.getConnection(Unknown Source)               at java.sql.DriverManager.getConnection(Unknown Source)               在myjava.Test.main(Test.java:13)

这是我的代码

    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();
                                }
                }

1 个答案:

答案 0 :(得分:0)

使用OpenShift Online MySQL盒式磁带时,您无法以" root"或者作为' @' localhost'。您必须使用OpenShift在安装MySQL盒式磁带时提供给您的凭据登录。您可以通过sshing到您的设备并运行命令env | grep MYSQL来查看凭据,或者您可以在OpenShift在线Web控制台中查看它们。有关在OpenShift Online上使用MySQL的更多信息,请参阅Developer Portal中的此文档(https://developers.openshift.com/databases/mysql.html)。