简体   繁体   English

拒绝访问远程MySQL连接请求

[英]Access denied to remote MySQL connection request

I have a mysql database (v5.5.41) setup on a remote server and an application connects to the DB from another server to run some queries. 我在远程服务器上安装了mysql数据库(v5.5.41),一个应用程序从另一台服务器连接到数据库以运行一些查询。 It's been working fine but recently my DB server got a new IP address. 一切正常,但是最近我的数据库服务器有了一个新的IP地址。 My application can't connect to the DB anymore, the connection times out. 我的应用程序无法再连接到数据库,连接超时。

The application is using the DNS name of the server, not a hard-coded IP, so there shouldn't be a problem. 该应用程序使用的是服务器的DNS名称,而不是硬编码的IP,因此应该没有问题。 In any case, if I run this from the application server: 无论如何,如果我从应用程序服务器运行此命令:

mysql -u app_user -h mydb.myhost.com -p

then I get 然后我得到

ERROR 1045 (28000): Access denied for user 'app_user'@'xxx.xxx.xxx.xxx' (using password: YES) 

If it was having trouble finding the new IP, then that command would probably just hang and timeout, so it seems to be an authentication issue. 如果在查找新IP时遇到问题,那么该命令可能只是挂起并超时,因此似乎是身份验证问题。 My password is definitely correct, but the application is using the same password as when the app was connecting successfully so it's not an issue of mistyping it. 我的密码绝对正确,但是该应用程序使用的密码与该应用程序成功连接时使用的密码相同,因此这不是误输入密码的问题。

I've tried deleting the user app_user from the database and re-creating, exactly as I did in the beginning: 我尝试从数据库中删除用户app_user并重新创建,就像开始时一样:

CREATE USER 'app_user'@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'mypassword';
GRANT SELECT ON mydb.* TO 'app_user'@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'mypassword' REQUIRE SSL;
FLUSH PRIVILEGES;

I'm not sure if the DB server IP change is just a coincidence, and maybe there's some other issue. 我不确定DB服务器IP更改是否只是一个巧合,也许还有其他问题。

The entry for app_user in select user, host from mysql.user shows the same IP address as in the Access Denied message above. select user, host from mysql.user中的select user, host from mysql.user app_user条目显示的IP地址与上面的Access Denied消息相同。 For what it's worth, I tried changing the DB user host to * and got Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server . 对于它的价值,我尝试将数据库用户主机更改为*并且Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server

Could this have something to do with SSL being required by connection attempts from this user? 这可能与该用户的连接尝试所需的SSL有关吗?

The problem was related to the REQUIRE SSL in the privileges for my user. 问题与我的用户权限中的REQUIRE SSL有关。 Without it, I could connect just fine. 没有它,我就可以正常连接。 I got things working again by putting my client-cert.pem and client-key.pem files on the application server, updated my.cnf by adding: 通过将我的client-cert.pem和client-key.pem文件放在应用服务器上,并通过添加以下内容更新了my.cnf ,我再次使工作正常:

ssl-cert = /path/to/client-cert.pem
ssl-key  = /path/to/client-key.pem 

...under the [client] section and restarted the mysql server. ...在[client]部分下,并重新启动了mysql服务器。

However, I still don't understand why I was able to connect successfully before when I had done none of these things. 但是,我仍然不明白为什么我在没有做任何这些事情之前就能成功连接。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM