Remote Connect MYSQL server using php.

How to remote Connect MYSQL server using local php.


1. First, you access the mysql using phpmyadmin or shell command.

mysql –u root –h your.mysql.server.address –p password
ps: The argument behind –u is username, -h is the hostname/host address and argument behind –p is the password. So substitute the respective argument.

2. You need to create user with % as domain and grant her access to the database.
The usr is the username you want to name it. The yourdb.* you should change to your database name.


CREATE USER ‘usr’@’%’ IDENTIFIED BY ‘some_pass’;
GRANT ALL PRIVILEGES on yourdb.* TO ‘usr’@’%’ WITH GRANT OPTION;



3. Then you now need to edit the my.cnf, you can easy find the mysql config file if you are using easyphp.



4. After open the file then you need to set the bind-address = your.mysql.server.address and comment out the skip-networking field.

5. Restart your mysql.

6. MySQL is using the port 3306 so if you have firewall you should let the inbound and outbound can using port 3306. (you can use iptables. make sure to open port for either everyone, or if you're in tight securety, then only allow the client address) If you are using windows 7, you can add rule on the port 3306 to allow inbound and outbound of the port.

7. Restart firewall.

You should able to access your mysql server remotely.




Remember edit the php .Your php file should have…

link = mysql_connect('your_my_sql_servername or IP Address', 'new_user_which_u_created', 'password');

if (!$link) {
die('Could not connect: ' . mysql_error());

}

echo 'Connected successfully';

mysql_select_db('sandsbtob',$link) or die ("could not open db".mysql_error());

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

Reading and Writing Operation of SRAM

Transmission Control Protocol (TCP)

File transfer from android to linux