Thursday, 12 June 2014

Allow Remote Connections to MySQL Database on Raspberry Pi

This article shows how to set up a MySQL database to allow remote client connections. This will allow other programs on remote computers to access the database.
The first step is to allow machines to connect. This is done by removing the bind-address line from the configuration file /etc/mysql/my.cnf

Once this is done restart the database to pick up the changes
/etc/init.d/mysql restart

Once the database is restarted, we need to create database user for the remote clients. We create a user called remoteuser.
CREATE USER 'remoteuser'@'%' IDENTIFIED BY 'remoteuser';

Next, we grant all permissions to remoteuser for our database, mydatabase
GRANT ALL ON mydatabase.* TO 'remoteuser'@'%';

Finally, we set the password for the user to 'remotepassword'.
SET PASSWORD FOR 'remoteuser'@'%'=password('remotepassword');

Now external clients can connect remotely to the database and should be able to execute commands against it.

No comments:

Post a Comment