<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rakesh G Sekhar</title>
    <description>The latest articles on DEV Community by Rakesh G Sekhar (@rakeshgsekhar).</description>
    <link>https://dev.to/rakeshgsekhar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F197142%2F74ca376f-ecd5-40ab-9f6c-76f41bdea22d.jpeg</url>
      <title>DEV Community: Rakesh G Sekhar</title>
      <link>https://dev.to/rakeshgsekhar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rakeshgsekhar"/>
    <language>en</language>
    <item>
      <title>How to Allow Remote Connections to MySQL Database on Ubuntu 20.04</title>
      <dc:creator>Rakesh G Sekhar</dc:creator>
      <pubDate>Mon, 13 Jul 2020 03:08:32 +0000</pubDate>
      <link>https://dev.to/rakeshgsekhar/how-to-allow-remote-connections-to-mysql-database-on-ubuntu-20-04-4nc2</link>
      <guid>https://dev.to/rakeshgsekhar/how-to-allow-remote-connections-to-mysql-database-on-ubuntu-20-04-4nc2</guid>
      <description>&lt;p&gt;In this article we will see how we can allow remote connection to MySQL database installed in our ubuntu 20.04 server. This can help you to manage your database from you desktop or laptops or even application running on your PC’s.&lt;/p&gt;

&lt;p&gt;Before we begin, you have to know how to establish an SSH connection to your server using putty. Here I am using a windows desktop. Open putty and provide IP address of your server and click open.&lt;/p&gt;

&lt;p&gt;It will ask for your username and password, provide it and click enter.&lt;br&gt;
Yeah! you just logged into your server.&lt;/p&gt;

&lt;p&gt;What’s next?&lt;br&gt;
It’s quite simple. First you have to change your MySQL configuration as by default MySQL will not be listening for external connections. For that just follow the bellow steps.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Determine the location of you MySQL config file. Run the below command to find the same.
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;mysql --help | grep "Default options" -A 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your will get an output like&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Default options are read from the following files in the given order : /etc/my.cnf   /etc/mysql/my.cnf   ~/my.cnf&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It’s the order in which MySQL looks for config file and let’s take the first dir path /etc/my.cnf.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. We will edit the &lt;strong&gt;/etc/my.cnf&lt;/strong&gt; file, for that run the below command.
&lt;/h4&gt;

&lt;p&gt;Note:- if you are not logged in with a user having root access, add &lt;strong&gt;sudo&lt;/strong&gt; before the command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo nano /etc/my.cnf&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Locate the line that contain [mysqlid].
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Don’t worry if your file is blank. Just add the following line to the file.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bind-address= xxx.ip.xxx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;replace &lt;strong&gt;xxx.ip.xxx&lt;/strong&gt; with your server ip. &lt;em&gt;Example 192.168.0.100&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Save the file by typing &lt;strong&gt;CTRL+O&lt;/strong&gt; will ask for confirmation click enter and the exit the editor by pressing &lt;strong&gt;CTRL+X&lt;/strong&gt;.
&lt;/h4&gt;

&lt;p&gt;Well that’s it. But for the config changes to take action, restart your MySQL server by running &lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo systemctl restart mysql&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;That’s all with the MySQL side, now we have to open MySQL port (default 3306) in the firewall for external connections. For that follow the below steps.&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Run the command below.
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;iptables -A INPUT -i enp1s0 -p tcp --destination-port 3306 -j ACCEPT&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Alternatively you can grant access to specific ip address.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iptables -A INPUT -i enp1s0 -s xxx.xxx.xxx.xxx -p tcp --destination-port 3306 -j ACCEPT&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;replace xxx.xxx.xxx.xxx with ip of the system from which you need to establish the connection. In my case I have provided the ip of my desktop.&lt;/p&gt;

&lt;p&gt;** Make sure the you replace enp1s0 with your network interface name. To find your network interface name, run ifconfig on terminal/putty, you can find it out.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Run the below command and save the iptables configuration.
&lt;/h4&gt;

&lt;p&gt;for IPv4 : &lt;code&gt;sudo iptables-save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;for IPv6 : &lt;code&gt;sudo ip6tables-save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It all done. Just reboot your system and try connecting from a deferent system.&lt;/p&gt;

&lt;p&gt;To reboot you can run sudo init 6 or sudo reboot.&lt;/p&gt;

&lt;p&gt;Thanks for reading,&lt;/p&gt;

&lt;p&gt;If you find any issues or corrections please update on the comment. I love to improve. 😊 &lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>database</category>
      <category>server</category>
      <category>mysql</category>
    </item>
  </channel>
</rss>
