How to add remote MySQL connection in linux?

Edit MySQL config file

  1. Use your appropriate editor to open the MySQL config file. In this tutorial, we will use a nano text editor. Perform the below command in order to open the config file.

    # sudo nano /etc/mysql/ mysql.conf.d/mysql.cnf
  2. The location of the config file may vary based on the version in use. Once you open the config file, go to the Bind-Address line. The default IP will be 127.0.0.1. You will need to change the IP address but make sure that the new IP address should match the server.

  3. Once you make the necessary changes in the file, save it and exit from the config file.

  4. In order to implement changes in the file, we need to restart the service.

    # sudo systemctl restart mysql


    Need to setup Firewall to allow remote connection

      1. If you have noticed, in the configuration file there is line “port =3306”. Now, we will need to open traffic for the specific port.

      2. Uncomplicated Firewall is the default tool in linux. Fire the below command to allow traffic and match IP.

        # sudo ufw allow from remote_ip_address to any port 3306
      3. The firewall tool in CentOS uses zones to dedicate what traffic is to be allowed. We’ll create a new zone to set the rules for the MySQL server traffic.

        # sudo firewall-cmd --new-zone=rule_name --permanent
        # sudo firewall-cmd --reload
        # sudo firewall-cmd -permanent --zone=rule_name --add-source=127.0.0.1
        # sudo firewall-cmd --permanent --zone=rule_name --add-port=3306/tcp
        # suo firewall-cmd --reload
      4. Now, we will open MySQL port along with iptables to unrestricted traffic.

        # sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
     
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

5 Wget Command Examples to Download Files in Linux.

wget is used to download your files from the remote server. It is used mostly on Linux...

Can I open APN port 2195 on my VPS?

You will get full administrative control of your VPS, therefore you can surely open/close any...

Can I purchase additional RAM, Disk space and Bandwidth for VPS?

Yes, you can purchase additional RAM(Our RAM Recommendation), DiskSpace, Bandwidth and vCPU...

Can I open APN port 2195 on my VPS?

You will get full administrative control of your VPS, therefore you can surely open/close any...

Difference Between su and sudo and How to Configure sudo in Linux VPS.

As we know Linux provides much better security. You can set user management policy and user...