How to allow remote access to databases
MySQL
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:
/etc/init.d/mysql restart
PostgreSQL
Configure PostgreSQL to listen for remote connections:
CONF=/etc/postgresql/8.3/main/postgresql.conf 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 0.0.0.0/0 md5 EOF
Restart PostgreSQL for the changes to take effect:
/etc/init.d/postgresql-8.3 restart
Comments
MySQL Alternative
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...
so in future, I'll be using
Anyway hope this is of help to someone