简体   繁体   English

远程MySql连接的访问​​被拒绝

[英]Access denied for remote MySql connection

I've recently built a PHP API (Slim-based) to allow my Android app to access a MySql database remotely. 我最近建立了一个PHP API(基于Slim),以允许我的Android应用程序远程访问MySql数据库。

Everything in the API is tested and ready to go locally, but now that I've uploaded it to the server, I keep getting "Access denied for user 'user'@'box431.bluehost.com' (using password: YES)" error, where 'user' is my correct database username. API中的所有内容都经过测试,可以在本地使用,但是现在我已将其上传到服务器,我不断收到“用户'user'@'box431.bluehost.com'用户的访问被拒绝(使用密码:是)”错误,其中“用户”是我正确的数据库用户名。

I tried deleting that user and creating a new one that has all permissions, to no avail, and the credentials in my config file - database name, user name, password, and host - are also correct. 我尝试删除该用户并创建一个拥有所有权限的新用户,但无济于事,而且我的配置文件中的凭据(数据库名称,用户名,密码和主机)也正确。 BlueHost is unable to help me any further, so now I turn to SO for help. BlueHost无法进一步帮助我,所以现在我向SO寻求帮助。

Any idea what else might be wrong?? 知道还有什么问题吗? I really only know how to access all these utilities via the cPanel, so any advice doing it through that view (or guidance if hardcoded changes needed) would be helpful. 我真的只知道如何通过cPanel访问所有这些实用程序,因此通过该视图进行操作的任何建议(或指导(如果需要进行硬编码的更改)都将是有帮助的)。

Thanks! 谢谢!

As it turns out, the solution was quite simple! 事实证明,解决方案非常简单! My config file had the host name set to the actual IP address, but it should have been "localhost" given that the web service and the database reside on the same server. 我的配置文件的主机名设置为实际IP地址,但是鉴于Web服务和数据库位于同一服务器上,因此它应该是“ localhost”。 Duh. 咄。 Hope this little detail is at least helpful for anyone else out there! 希望这个小细节至少对其他人有帮助!

I'm not sure how to achieve this using cPanel but I think where you're going wrong is the mySQL user hasn't been configured for remote access. 我不确定如何使用cPanel实现此目的,但我认为您出了问题的地方是尚未配置mySQL用户进行远程访问。 You can use the following syntax with the mySQL CLI. 您可以在mySQL CLI中使用以下语法。

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'YourPassword' WITH GRANT OPTION;

You'll need to follow that with the following; 您需要遵循以下内容;

FLUSH PRIVILEGES;

As Giles pointed out in his comment this is not particularly secure, you'd be better off creating a web service to manipulate the database. 正如Giles在他的评论中指出的那样,这并不是特别安全,因此最好创建一个Web服务来操纵数据库。

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

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