[英]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()]
,我得到了
bugs@<my laptop IP>
bugs@<my laptop IP>
bugs@%
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
。
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.