首页 文章

Acess拒绝用户连接Mysql java

提问于
浏览
0

当我试图与在线mysql数据库连接时,我收到此错误:

java.sql.SQLException:用户''@ '89 .229.59.50'拒绝访问(使用密码:否)

我的代码是:

public static Statement stmt = null;
 public static Connection conn = null;
 private static final String dbURL ="jdbc:mysql://db4free.net:3306/dolar;user=neir@localhost&password=password";

 private static void createConnection() {
    try {
       conn = DriverManager.getConnection(dbURL);       
    } catch (Exception except) {
        except.printStackTrace();
    }
}

是的,我已经为我的项目添加了mysql连接器 .

3 回答

  • 0

    您必须确保用户(neir)具有远程访问权限 .

    如果您使用托管服务,请确保他们允许您的远程IP(89.229.59.50)连接到MySQL服务器 .

    如果你正在管理MySQL服务器,请确保它被配置为远程访问,这是在my.cnf文件中完成的,搜索并注释该行:

    bind-address = 127.0.0.1

    希望这可以帮助 .

  • 0

    从错误中您已经可以看到未使用用户和密码参数 . 这可能会让您知道JDBC连接URL有问题 .

    您不能将用户和密码参数放在连接URL中 . 你应该使用: getConnection(String url, String user, String password)

    见:https://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html#getConnection-java.lang.String-java.lang.String-java.lang.String-

  • 0

    这可能是因为用户没有访问权限,所以你应该这样做 .

    CREATE USER 'enterusername'@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'enterpassword';
    

    如果xxx.xxx.xxx.xxx是你的IP,或者你想为任何IP做这个,那么只需写'%'而不是'xxx.xxx.xxx.xxx'

    授予权限

    GRANT ALL PRIVILEGES ON mor.* TO 'enterusername'@'xxx.xxx.xxx.xxx' WITH GRANT OPTION ;
    

相关问题