简体   繁体   English

用户的mysql访问的JDBC连接错误被拒绝 <user> @ <host>

[英]JDBC Connection error to mysql Access Denied for user <user>@<host>

I have already checked the other Stack Overflow and web links on this: 我已经检查了其他关于此的Stack Overflow和Web链接:

MySQL is on a Linux server MySQL在Linux服务器上

Linux uslx600 2.6.32-358.14.1.el6.x86_64 #1 SMP Mon

Says its IP is 1.2.3.4 说它的IP是1.2.3.4

I can connect to it from my laptop using MySQL Workbench. 我可以使用MySQL Workbench从笔记本电脑连接到它。 I cannot attach image due to Stack Overflow policy, but the dialog is as follows: 由于堆栈溢出策略,我无法附加图像,但是对话框如下:

Connection Method: tcp/ip  
Hostname: <host of the server, so e.g. 1.2.3.4>  
Port: 3306 <This is same port as mentioned below for JDBC connection>  
username: bugs  
Default Schema: bugs  

Within that mysql I ran [select user(), current_user()] , I get 在该mysql中,我运行了[select user(), current_user()] ,我得到了

  • user() = bugs@<my laptop IP> user()= bugs@<my laptop IP>
  • current_user() = bugs@% current_user()= bugs@%

Now I am trying to connect from the Linux server where the MySQL database is. 现在,我正在尝试从MySQL数据库所在的Linux服务器进行连接。

Following works, user is user by itself, ie no "@%" or something: 在完成以下工作后,用户本身就是用户,即没有“ @%”之类的东西:

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bugs", user, pasword);

Following also works: 以下内容也适用:

conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/bugs", user, pasword);

But it does not work, if I give the IP address of the box or hostname. 但是,如果我提供了机器的IP地址或主机名,那是行不通的。 And what I am really working towards is accessing this from another Linux server, which does not work either probably due to same issue. 我真正要努力的是从另一台Linux服务器访问此服务器,这可能由于相同的问题而无法正常工作。

The error message when it fails is: 失败时的错误消息是:

Access Denied for user 'bugs'@'<hostname of the server>' (using password=YES)

If there was some access issue on the server, shouldn't the MySQL Workbench have the same issue? 如果服务器上存在访问问题,那么MySQL Workbench是否应该有相同的问题?
And current_user() says bug@% so does it not imply that user is setup correctly? 而且current_user()表示bug@% ,是否不表示用户设置正确?

I have also tried changing user to 'user'@'%' etc., but in all those cases error message was always: 我也尝试将用户更改为'user'@'%'等,但是在所有这些情况下,错误消息始终是:

'bugs'@'%'@'<hostname>'

Make sure you have granted all privileges to all hosts. 确保已将所有特权授予所有主机。

Check your my.cnf file and comment out bind-address if it's pointing to 127.0.0.1 only. 检查您的my.cnf文件,如果它仅指向127.0.0.1,则注释掉bind-address

MySQL root access from all hosts 来自所有主机的MySQL根访问

The error says that it cannot connect to the server with the given password. 该错误表明它无法使用给定的密码连接到服务器。 May be your password is incorrect or if it is having special characters, you have to escape that string properly. 可能是您的密码不正确,或者包含特殊字符,则必须正确转义该字符串。

Another thing, the user bugs could not have privilege to connect to the server from the specified host. 另一件事,用户错误没有权限从指定的主机连接到服务器。 Try providing GRANTS to the user from the host you are connecting and then check if you are able to connect to MySQL. 尝试从要连接的主机向用户提供GRANTS,然后检查是否能够连接到MySQL。

GRANT ALL PRIVILEGES ON *.* TO 'bugs'@'%' IDENTIFIED BY 'password';

or comment the line in my.cnf file 或注释my.cnf文件中的行

#bind-address = 127.0.0.1 

restart mysql service. 重启mysql服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JDBC 连接到 MySql 错误 - 用户 'root'@'localhost' 的访问被拒绝(使用密码:否) - JDBC Connection to MySql error - Access denied for user 'root'@'localhost' (using password: NO) com.mysql.jdbc.exceptions.jdbc4.MysqlSyntaxErrorException:用户&#39;@&#39;本地主机&#39;对数据库&#39;mysql&#39;的访问被拒绝 - com.mysql.jdbc.exceptions.jdbc4.MysqlSyntaxErrorException:Access denied for user "@'local host' to database 'mysql' 在jdbc连接java中设置mysql用户主机 - Set mysql user host in jdbc connection java Java中的MySQL连接:用户@本地访问被拒绝 - Mysql Connection in Java: Access denied for user @ localhost 用户 'user'@'localhost' 的访问被拒绝(来自 Intellij 的 MySQL 数据库连接错误) - Access denied for user 'user'@'localhost' (MySQL DB connection error from Intellij) 在mysql中拒绝用户访问 - Access denied for user in mysql Java-没有密码的用户的mysql访问被拒绝错误 - Java - mysql access denied error for user with no password 使用 Spring 和 JDBC,为什么我会因用户错误而拒绝访问? - with Spring and JDBC, why am I getting Access denied for user error? 用户 'root'@'localhost' 的访问被拒绝 - Spring 引导和 MySQL 连接 - Access Denied for user 'root'@'localhost' - Spring Boot & MySQL connection Mariadb连接客户端:在mysql 8.0上拒绝用户访问(使用密码:NO) - Mariadb connection client: Access denied for user (using password: NO) on mysql 8.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM