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");