1

I have some existing code in php for server side coding and the db is MySql. Both resides on the production(realtime) database.

Some job is given to me to fetch the records from the actual server and display in some format on local machine. I cannot duplicate the data onto my local system due to security reason. Any ideas how can i connect to production server and get my query run. I am ready to recreate the server side coding also....any help is appreciated....

4

1 回答 1

0

You will need to grant access to the production machine from your local machine. You can do so by granting all privileges on your IP address. For example, if your username was remote and your public IP address was 10.1.0.8, you would use this:

GRANT ALL PRIVILEGES ON *.* TO remote@'10.1.0.8';
FLUSH PRIVILEGES;

Remember to flush your updated privileges!

You can now connect to the production machine using PHP. For example, if your production machine was at production.example.com, you would use this:

mysql_connect("production.example.com", "remote", "My-p@ssw0rd");
mysql_select_db("example_db");

If you don't have root access to the production machine or can't grant privileges for some reason, you can also try to set up an SSH tunnel, if you have access to SSH.

Instructions on how to set up an SSH tunnel can be found here (Windows/PuTTY).

You can then connect to whatever you used as local port using PHP as PuTTY will route all traffic through its SSH tunnel to the remote production server, making the production server to believe you connected from localhost:

mysql_connect("localhost", "remote", "My-p@ssw0rd");
mysql_select_db("example_db");
于 2013-06-09T17:12:31.210 回答