gpt4 book ai didi

java - 用户 'user' @'localhost' 的 MySQL 访问被拒绝(使用密码 : yes) "openshift"

转载 作者:行者123 更新时间:2023-11-29 21:09:17 24 4
gpt4 key购买 nike

我想使用 java 连接到 openshift 服务器中托管的 mysql 数据库。在我的本地计算机上一切正常,但是当我尝试连接到 openshift 数据库时,我收到此错误

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)

这是我的代码

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

最佳答案

使用 OpenShift Online MySQL 盒时,您无法以“root”或“user”@“localhost”身份登录。您必须使用安装 MySQL 盒时 OpenShift 提供给您的凭据登录。您可以通过 sshing 进入您的设备并运行命令 env | 查看凭据。 grep MYSQL,或者您可以在 OpenShift Online Web 控制台中查看它们。有关在 OpenShift Online 上使用 MySQL 的更多信息,请参阅开发者门户中的此文档 ( https://developers.openshift.com/databases/mysql.html )。

关于java - 用户 'user' @'localhost' 的 MySQL 访问被拒绝(使用密码 : yes) "openshift",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36535494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com