【问题标题】:Java JDBC Access denied for user [closed]用户的 Java JDBC 访问被拒绝[关闭]
【发布时间】:2011-11-22 09:55:08
【问题描述】:

我正在尝试从我的 java 应用程序连接到 MySQL,但它一直在说:

java.sql.SQLException: 用户 'vincent'@'x.x.x.x' 的访问被拒绝 (使用密码:YES)

我已经在 phpmyadmin 中检查了 vincent 可以从任何主机连接,并且我还有一个 python 脚本可以毫无问题地使用相同的用户名/密码进行连接

有什么问题?

非常感谢

问候。

【问题讨论】:

  • 您可以使用mysql 命令行工具从您尝试运行 Java 应用程序的主机连接到 x.x.x.x 吗?

标签: java mysql jdbc


【解决方案1】:

尝试从 mysql 中的任何机器向您的用户授予所有权限:

 grant all on db_name.* to ‘vincent’@'%';

其中 db_name 是您的数据库名称 ...

【讨论】:

    【解决方案2】:

    这是我授予权限的方式:

    create database foobar;
    create user foobar identified by 'foobar';
    grant all on foobar.* to 'foobar'@'%' identified by 'foobar';
    grant all on foobar.* to 'foobar'@'localhost' identified by 'foobar';
    

    您还需要用户的主机。

    【讨论】:

      【解决方案3】:

      使用这个

      GRANT ALL PRIVILEGES ON db_base.* TO db_user @'%' IDENTIFIED BY 'db_passwd';
      

      您必须授予 db 上的用户访问权限。是的,如果您正在使用用户定义的存储过程和函数,那么也使用

      GRANT SELECT ON mysql.proc TO 'db_user'@'%';
      

      【讨论】:

        【解决方案4】:

        获取连接对象时必须指定useridpassword

        Connection cn=DriverManager.getConnection("protocol","userid","password");
        

        【讨论】:

          猜你喜欢
          • 2017-03-14
          • 1970-01-01
          • 1970-01-01
          • 2017-08-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-23
          相关资源
          最近更新 更多