开发者

Mysql - connect to remote server using IP address

开发者 https://www.devze.com 2023-04-12 23:21 出处:网络
I am using PHP and MySQL to make a database connection, the only change is开发者_Go百科 that I am trying to access my remote server from my local computer using my server IP address.

I am using PHP and MySQL to make a database connection, the only change is开发者_Go百科 that I am trying to access my remote server from my local computer using my server IP address.

mysql_connect("x.xx.xx.x","username","password") or die(mysql_error());

and the error I am getting is Unable to connect to the given host. The user has all privileges and rights.


Most default installs of MySQL only listen to the local machine.

Look for the bind-address setting in my.cnf on the server, and make sure it's listening on the IP address you're targetting. You may also need to ensure skip-networking isn't switched on!

Alternatively (and less securely!) the following will set it up to listen on all addresses - local and remote:

bind-address = 0.0.0.0


Before you try using PHP todo this. Open up your terminal or console and type the following:

$ mysql -u username -h x.xx.xx.x -p

then enter your password

Or on windows then type:

\path\to\mysql.exe -u username -h x.xx.xx.x -p

then enter your password

This will give you a more detailed response as to the authentication issue that's coming up. And you can be 100% sure that your remote login from your IP address works. If it works fine then its something in your PHP code that you're missing.


Try to add a user (USER-NAME) allowed to connect from the IP:

mysql> GRANT ALL PRIVILEGES ON *.* TO USER-NAME@IP IDENTIFIED BY "PASSWORD";

USER-NAME is the username that you would like to create (like 'widor') IP is the public IP address of your remote connection (like '195.x.y.z')

Of course, limit the privileges you want to grant (ALL PRIVILEGES is probably not your choice)


1) Check which interface MySQL listen for connections, local (localhost, 127.0.0.1) or remote (0.0.0.0 or IP address). It's in my.cnf. http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

2) Check does your user have corresponding privileges. User that logs in from localhost can have different priveleges from remote one. For example 'user'@'localhost' and 'user'@'%'

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号