问题
I'm trying to connect from my ip address to a mobile web app I'm helping to fix so I can test it on my Android phone. However, while the login screen shows up when I access it from localhost AND my ip address, it will only let me login from the localhost address- it doesn't even connect from the ip address.
I'm running MAMP Pro and have unchecked the "Allow local access only". I went into MySQL my.cnf and changed the bind-address from 127.0.0.1 to my own IP. I also commented out the "MAMP_skip-networking_MAMP" line. I then made a user that matches up with the user in config.php, has full access to the database, and set their host to %.
In the config.php file, I've tried changing the hostname to:
- localhost
- localhost:[PORT NUMBER]
- [IP ADDRESS]
- [IP ADDRESS]:[PORT NUMBER]
- /Applications/MAMP/tmp/mysql/mysql.sock
Still.. nothing. I still can't login when I try to access the site from my IP. Any help/direction would be greatly appreciated.. thank you!
回答1:
The issue isn't with the client, most likely, but with the server. Most MySQL servers are configured (I think by default) to refuse connection attempts that aren't local. Give me a few seconds to pull up the config/info schema change to make so that you can change this.
Warning, it's a bad idea to open up the db to all requests. You'll want to either make it open to all IP requests from one user, or allow requests from any user from a specific IP (or even better, combine the two and make it so that only certain users can make requests from specific IPs).
Here's a good (but again dangerous) tutorial:
how-do-i-enable-remote-access-to-mysql-database-server
The simple way to do it, if I'm not mistaken, is to run the following queries: (assuming you're as "superadmin":
USE information_schema;
UPDATE USER_PRIVILEGES SET Host='%' WHERE user='superadmin';
FLUSH PRIVILEGES;
USE mysql;
UPDATE user SET Host='%' WHERE user='superadmin';
The above basically grants the superadmin access to the mysql db (if not already granted), then the switch to that db and grant superadmin access from any IP. Again, follow the links provided to see how to tweak this per user and per IP, otherwise you are opening up yourself to a world of hurt just to use a nifty MySQL GUI.
It may be more complicated than the above (a restart may be required, etc.). Another good article is:
MySQL - Adding Users -- look for the section mentioning wildcards.
来源:https://stackoverflow.com/questions/10765783/mysql-can-connect-locally-but-not-remotely