Andy Jarrett // Code. Develop. Create.

Getting Remote Access to MySQL

After setting up my server yesterday, I encountered an issue with getting remote access to MySQL. It felt as if MySQL wasn't even running.

After some digging around and pestering a Linux user (pro tip: always have a nix admin friend, and be sure to buy him a scotch or two as a thank-you), I discovered that MySQL was indeed running. The problem was that it wasn’t bound to the machine’s IP address but instead to localhost.

By default, remote access is disabled for security reasons, but there are times when you need to enable it for one reason or another. Here's how you can enable remote access:

Steps to Enable Remote Access to MySQL

  1. Login via SSH

    Start by logging into your server using SSH.

  2. Edit the MySQL Configuration File (my.cnf)

    On Ubuntu, you can edit the MySQL configuration file by running:

    $ sudo nano /etc/mysql/my.cnf

    Depending on your distribution, the path might vary. For instance, it could be /etc/mysql/mysql.conf.d/mysqld.cnf on newer versions of Ubuntu.

  3. Modify the bind-address Setting

    Once the file is open, look for the line:

    bind-address = 127.0.0.1

    Change this to your server's IP address. For example, if your server's IP is 10.0.1.1, update the configuration as follows:

    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address = 10.0.1.1

    This change tells MySQL to listen on the specified IP address, allowing remote access from that IP.

  4. Restart MySQL Service

    After making the changes, save the file and close the editor. Then, restart the MySQL service to apply the changes:

    $ sudo /etc/init.d/mysql restart

    Alternatively, on systems using systemd, you might use:

    $ sudo systemctl restart mysql

By following these steps, you should now have remote access enabled on your MySQL server. Always ensure that your MySQL server is secured with strong passwords and, if possible, restrict access by IP to prevent unauthorized access.

I’m here, learning and working away. If you liked this content and want to keep me going, consider buying me a coffee. Your support keeps this site running and the coffee brewing! ☕️