简体   繁体   中英

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.

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.

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.

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.

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. 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. You can use the following syntax with the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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