Local MySQL Database Online

Posted on 11-06-2011 00:00

Some people might find themselves in need to get a database they have installed on localhost online, so they can test something on their online site, like security or speed.

I found myself in that exact position a few weeks ago and took me a while to figure this out, so i decided to share it with you and save someone's time!

  • Fire up the terminal!:
    su 
    Keep this terminal open, since both following commands require root privileges

    nano /etc/mysql/my.cnf
  • Find lines 43 and 47 and comment them:
    # skip-external-locking 
    # bind-address = localhost
    
    (non-debian distros, make sure that skip networking is commented out)
  • Now visit your phpmyadmin and set a new user with all privileges. (Privileges->Add new user)
    Be careful though to set to the host field the IP adrress or domain name of your site (the one you want to test the database with), or select Any host (%).
  •  After that all you need to do is to restart mysql server:

    /etc/init.d/mysql restart
  • If you still can't connect then you must open up port 3306:

    /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT


    and then

    /etc/init.d/iptables save 
    (remember to restart mysql again)

Please feel free to drop a comment if something goes wrong!