Allowing Network Access to MariaDB Database

Answered using GPT-4o by GPT4oMini.app

Question:

I have create a mariaDB database in a server. How to change bind-address such that pc from the same network is allowed to connect to this db?

Answer:

To allow other PCs on the same network to connect to your MariaDB database, you need to modify the bind-address setting in the MariaDB configuration file. Here’s how you can do it:

  1. Locate the Configuration File:

    • The MariaDB configuration file is usually located at /etc/mysql/my.cnf or /etc/my.cnf. You might also find it in /etc/mysql/mariadb.conf.d/50-server.cnf on some systems.
  2. Edit the Configuration File:

    • Open the configuration file with a text editor. You might need superuser privileges to edit this file. For example, you can use nano or vi:
      sudo nano /etc/mysql/my.cnf
      
      or
      sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
      
  3. Modify the bind-address:

    • Look for the line that starts with bind-address. It might look like this:
      bind-address = 127.0.0.1
      
    • Change the bind-address to 0.0.0.0 to allow connections from any IP address on the network:
      bind-address = 0.0.0.0
      
    • Alternatively, you can specify a specific IP address of the server that is accessible from your network.
  4. Save and Exit:

    • Save the changes and exit the text editor. In nano, you can do this by pressing CTRL + X, then Y to confirm changes, and Enter to exit.
  5. Restart MariaDB Service:

    • For the changes to take effect, restart the MariaDB service:
      sudo systemctl restart mariadb
      
    • On some systems, the service might be named mysql instead of mariadb:
      sudo systemctl restart mysql
      
  6. Configure Firewall (if necessary):

    • Ensure that your firewall allows incoming connections on the MariaDB port (default is 3306). You can use ufw or iptables to configure this. For example, with ufw:
      sudo ufw allow 3306/tcp
      
  7. Grant Access to Users:

    • Make sure that the MariaDB user has the necessary privileges to connect from other hosts. You can grant access using the following SQL command:
      GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password';
      FLUSH PRIVILEGES;
      
    • Replace 'username' and 'password' with the actual username and password.

By following these steps, you should be able to allow other PCs on the same network to connect to your MariaDB database.