Connecting PHP to MYSQL Database in another machine

If you had webserver and you had another mysql that hosting your database, and it is kept in another machine and you want to connect it via your local area network, so you need to grant access for remote connection on that mysql.

Please run the following script on SQL command at that mysql database :

GRANT ALL PRIVILEGES ON [dbname].* to
                ‘[user]’@'[hostname]’ identified by
                ‘[password]’

Note : replace [dbname] with your database name, replace [user] with your username or you can put root as default, replace [hostname] with your computer IP/name that act as your webserver, and replace [password]  with your password that set at the beginning.

For doing some testing, you can try the following command (command prompt) at your computer that act as webserver :

telnet xxx.xxx.xxx.xxx 3306 <enter>

Note : if you don’t see the message that the computer (hosted mysql database)  refuse your connection directly, it means your connection to that mysql database can be established.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: