How to allow remote access to databases


Configure MySQL to listen for remote connections:

sed -i "s/^bind-address/#bind-address/" /etc/mysql/my.cnf

Configure MySQL to accept remote root connections (from any host ('%')):
(added line breaks for readability)

MYSQL_BATCH="mysql --user=root --password=$MYSQL_PASS --batch"
$MYSQL_BATCH --execute "INSERT INTO mysql.user ( Host , User , Password , Select_priv ,
    Insert_priv , Update_priv , Delete_priv , Create_priv , Drop_priv , Reload_priv , 
    Shutdown_priv , Process_priv , File_priv , Grant_priv , References_priv , 
    Index_priv , Alter_priv , Show_db_priv , Super_priv , Create_tmp_table_priv , 
    Lock_tables_priv , Execute_priv , Repl_slave_priv , Repl_client_priv , 
    Create_view_priv , Show_view_priv , Create_routine_priv , Alter_routine_priv , 
    Create_user_priv , ssl_type , max_questions , max_updates , max_connections , 
    max_user_connections) VALUES ( '%', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y',
    'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y', 'Y', 'Y',
    'Y', 'Y', 'Y', 'Y', '', '0', '0', '0', '0');"

Restart MySQL for the changes to take effect:

service mysql restart



Configure PostgreSQL to listen for remote connections:

sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" $CONF

Configure PostgreSQL to accept remote connections (from any host):

# configure postgres to accept remote connections
cat >> /etc/postgresql/8.3/main/pg_hba.conf <<EOF
# Accept all IPv4 connections - CHANGE THIS!!!
host    all         all             md5

Restart PostgreSQL for the changes to take effect:

/etc/init.d/postgresql-8.3 restart



Simon O's picture

Hi All,

I'm by no means an expert so please bear in mind this is simply my own experience

I found it far easier to run the sed command, then use the web interface to change the host for the user in question to % (aka all/any).

NB: If you do this via the command line, note that the block above after "(added line breaks for readability)" is actually 2 commands - I'm sure this is obvious to most readers but caught me out for a minute or 2

You can do this either through Webmin or phpMyAdmin)

I still had to restart MySQL (I assume for the binding to apply). The restart command listed above barfed on me...


~# /etc/init.d/mysql restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the restart(8) utility, e.g. restart mysql

so in future, I'll be using

restart mysql

Anyway hope this is of help to someone

Marco Ovalle's picture


ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
This error appears when Inserting sentece is executed.... Why?... 
Landis Arnold's picture

Rather than allowing "any", what is the process for allowing, perhaps "2" external IP's and Localhost?  So far by just adding a "host" in webmin I am still not getting the allowance.

Landis Arnold's picture

Rather than messing with the fundamental setup I took some advice out (here) and added 2 Host Files, and 1 new MySQL User.  I gave each pretty much fullrights within WEBMIN MySQL server.

I found I could then access the data with FileMaker via ODBC from one of the IP's where I could not before the setup.  Navicat also has this new option as well as the "no setup" option or the MySQL over SSH option.

I am inclined to recomend against stimply Opening up Access to "all" hosts.  If you assign access to your own Gatewa'ys IP address (if it is fixed) this should work.  With a floating IP ou can likely also get a entry to work with a floating IP if you use TKL's Dynamic DNS or similar service.

Newbie's picture

Using Google Apps Scripts JDBC with MySQL requires remote access from an extensive range of IP addresses like: - - - - - - - - - -

For 0 - 255 I could use %. But how about the address ranges like - Can CIDR be used in the INSERT INTO? 

Jeremy Davis's picture

However the current TKL (v13.0) is based on Debian Wheezy (aka Debian 7) so anything that applies there should apply to TKL. Google probably has some ideas...

If you find a good solution be great if you could post back as it will help others in the future no doubt! :)

Ammar Surti's picture


can someone tell me how can i do this with the web interface. I am trying to connect mysql database on a visual studio application using C-sharp. I am literelly stuck at this point and cant find my way out. I have never worked with linus so i have no clue how to proceed with the commands above.

I hope someone could get back as soon as possible.


Jeremy Davis's picture

TBH I haven't tested doing it with Webmin but it should be possible.

FWIW if you log in via SSH (using an SSH client like PuTTY if you are on Windows) then it should be as simple as copy pasting the above commands in and then is should all just work.

But if you would rather use Webmin, then when you are logged into Webmin, from the top bar select "Servers" >> "MySQL Database Server". You'll then need to use your MySQL root password to get access. Once you are in select "MySQL Server Configuration". Then next to "MySQL server listening address" select "All" (defaults is

You'll probably also need to update the permissions for the user but I'm not sure how to do that from Webmin. I would suggest that Adminer would be better for that task (https on port 12322). Hopefully that's enough to get you going.

Also FWIW it's generally better to post in the forums (rather than comment on a doc page) as I only get one email notification when you post here. If I miss that and/or it gets buried in my inbox, then I'll possibly never see it. At least in the forums it shows up in the forum list.

Ammar Surti's picture

Thank you Jeremy, much appreciated.

I will try your method and you are right, now the setting for the listening address is set at, so i will change that to any and proceed from there. 

And yes, i will post my questions on the forums. Thank you