Forum Moderators: open
I have a mysql database on my local installation of WAMP. To access this database I would use something like this:
$link = mysql_connect('localhost', 'root', 'root');
If I wanted to access this same database from a remote server what would I use? Do I just replace localhost with the ip address of my machine?
Thanks!
this is probably a good place to start:
MySQL :: MySQL 5.1 Reference Manual :: B.1.2.2 Can't connect to [local] MySQL server:
[dev.mysql.com...]
you will probably have to GRANT [dev.mysql.com] some privileges to remote users.
1. Created a user in phpmyadmin and granted them all global privleges and from any host.
2. Used the following script to try and connect to the database from my remote server:
<?php
$dbServer1='99.99.999.999';// username and password to log onto db server
$dbUser1='username';
$dbPass1='password';
// name of database
$dbName1='databasename';
$link = mysql_connect("$dbServer1", "$dbUser1", "$dbPass1") or die("Could not connect");
print "Connected successfully to your_db_name1<br>";
mysql_select_db("$dbName1") or die("Could not select database your_db_name1");
print "Database your_db_name1 selected successfully<br><br><br>";
// close connection
mysql_close($link);
?>
I added the ip address of my local machine and the username and password of the user I created in phpmyadmin to the appropriate places.
When I run the script I get the following error:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '99.99.999.999' (4) in /home/toomany2/public_html/testdbconnection.php on line 29
Could not connect
When testing I turned off my firewall and plugged my computer directly into the modem.
If I change the server to localhost and run it locally it connects no problem.
The remote machine is running OS X if that makes any difference.
Have I missed something to allow the remote connection?
Thanks