{"id":73,"date":"2008-11-23T16:40:41","date_gmt":"2008-11-23T09:40:41","guid":{"rendered":"http:\/\/blog.binus-edu.com\/?p=73"},"modified":"2009-04-02T11:01:55","modified_gmt":"2009-04-02T04:01:55","slug":"how-to-allow-external-connections-remote-access-to-mysql-database-server","status":"publish","type":"post","link":"https:\/\/adityo.blog.binusian.org\/?p=73","title":{"rendered":"How to Allow external connections Remote Access To MySQL Database Server?"},"content":{"rendered":"<h2>What is MySQL ?<\/h2>\n<p>MySQL is a relational database management system (<a class=\"inline\" href=\"http:\/\/searchsqlserver.techtarget.com\/sDefinition\/0,,sid87_gci214260,00.html\">RDBMS<\/a>) based on <a class=\"inline\" href=\"http:\/\/searchsqlserver.techtarget.com\/sDefinition\/0,,sid87_gci214230,00.html\">SQL<\/a> (Structured Query Language). First released in January, 1998, MySQL is now one component of parent company MySQL AB&#8217;s product line of database servers and development tools.<\/p>\n<p>MySQL version<\/p>\n<p>i assume you have installed mysql before, if not you can use yum install mysql* to installed it<\/p>\n<p>[root@adityo ~]# rpm -qa | grep mysql<br \/>\nmysql-5.0.45-7.el5<br \/>\nmysql-server-5.0.45-7.el5<\/p>\n<p>Btw i am using Heidisql version 3.2 (http:\/\/heidisql.googlecode.com\/files\/HeidiSQL_3.2_Setup.exe) as my mysql client program<\/p>\n<p>By default, MySQL database server remote access disabled for security reasons. However, some time you need to provide the remote access to database server from home or from web server. You will see this error when you access it.<\/p>\n<p><img decoding=\"async\" style=\"width: 580px; height: 217px;\" src=\"http:\/\/blog.binus-edu.com\/wp-content\/uploads\/heidi(1).jpg\" alt=\"\" \/><\/p>\n<p><em>what you need to do ?<\/em><\/p>\n<p>Grant access to remote IP address<\/p>\n<p><code># mysql -u root -p mysql<\/code><\/p>\n<p>If you want to add new database called test for username testing and remote IP 202.54.11.24 then you need to type following commands<\/p>\n<p>\/\/Create a new database name test<\/p>\n<p><code>mysql&gt; CREATE DATABASE test;<\/code><\/p>\n<p><code>\/\/Grant access to test user that comes from <\/code><code>202.54.11.24<\/code><code><br \/>\nmysql&gt; GRANT ALL ON foo.* TO test@'202.54.11.24' IDENTIFIED BY 'PASSWORD';<\/code><\/p>\n<p><strong><code>if you want <\/code>add root access to all database you can use this command<\/strong><\/p>\n<p><code>\/\/grant access to user-remote host combination<br \/>\n<\/code><code>mysql&gt;<\/code><code>GRANT USAGE ON *.* to root@'<\/code><code>202.54.11.24<\/code><code>' IDENTIFIED BY 'newpassword';<\/code><\/p>\n<p><code>Grant all priviledges to the user so you can see all database and udpate it<\/code><\/p>\n<p><code>mysql&gt;<\/code><code>grant all privileges on *.* to <\/code><code>root@'<\/code><code>202.54.11.24<\/code><code>'<\/code><code> ;<br \/>\n\/\/force update of authorization changes<br \/>\n<\/code><code>mysql&gt;<\/code><code>FLUSH PRIVILEGES; <\/code><\/p>\n<p>Now you can access it again<\/p>\n<p><img decoding=\"async\" style=\"width: 587px; height: 342px;\" src=\"http:\/\/blog.binus-edu.com\/wp-content\/uploads\/heidi3.jpg\" alt=\"\" \/><\/p>\n<p><strong>If you still cannot access the mysql remotely you need to checked the firewall<\/strong><\/p>\n<p>you can test the connection by typing this on\u00a0 your command prompt<\/p>\n<p>telnet 202.54.11.24 3306<\/p>\n<p>Connecting To 202.54.11.24&#8230;Could not open connection to the host, on port 33<br \/>\n06: Connect failed<\/p>\n<p>it means\u00a0 you need to open port 3306 using iptables<\/p>\n<h4>A sample iptables rule to open Linux iptables firewall<\/h4>\n<pre><code>\/sbin\/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT<\/code><\/pre>\n<p>OR only allow remote connection from your web server located at 202.54.11.24:<\/p>\n<pre>\/sbin\/iptables -A INPUT -i eth0 -s 202.54.11.24 -p tcp --destination-port 3306 -j ACCEPT<\/pre>\n<p>OR only allow remote connection from your lan subnet 192.168.1.0\/24:<\/p>\n<pre>\/sbin\/iptables -A INPUT -i eth0 -s 192.168.1.0\/24 -p tcp --destination-por\r\n\r\n<strong>If you still cannot connected , please checked the my.cnf on \/etc\/my.cnf<\/strong><\/pre>\n<p>Make sure line skip-networking is commented (or remove line) and add following line<\/p>\n<p>bind-address=YOUR-SERVER-IP<\/p>\n<p>For example, if your MySQL server IP is 65.55.55.2 then entire block should be look like as follows:<br \/>\n<code>[mysqld]<br \/>\nuser            = mysql<br \/>\npid-file        = \/var\/run\/mysqld\/mysqld.pid<br \/>\nsocket          = \/var\/run\/mysqld\/mysqld.sock<br \/>\nport            = 3306<br \/>\nbasedir         = \/usr<br \/>\ndatadir         = \/var\/lib\/mysql<br \/>\ntmpdir          = \/tmp<br \/>\nlanguage        = \/usr\/share\/mysql\/English<br \/>\nbind-address    = 65.55.55.2<br \/>\n# skip-networking<br \/>\n....<\/code><\/p>\n<pre>\u00a0Then do not forget to restart the mysql service\r\n#service mysqld restart<\/pre>\n<pre>How to test the connection from your mysql server ?\r\n\r\nYou can use the mysql command\r\n mysql -h hostname address -u username -p then enter password<\/pre>\n<p>example:<\/p>\n<p># mysql -h 203.48.184.101 -u root -p<br \/>\nEnter password:<br \/>\nWelcome to the MySQL monitor.\u00a0 Commands end with ; or g.<br \/>\nYour MySQL connection id is 5714<br \/>\nServer version: 5.0.51a-3ubuntu5.4 (Ubuntu)<\/p>\n<p>Type &#8216;help;&#8217; or &#8216;h&#8217; for help. Type &#8216;c&#8217; to clear the buffer.<\/p>\n<p>mysql&gt; show databases;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Database\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| information_schema |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n1 rows in set (0.01 sec)<\/p>\n<p>mysql&gt;<\/p>\n<p>If you only see information_schema database on your mysql source target (\u00a0in example i use  203.48.184.101 ) but there actualy 6 database on the  203.48.184.101it&#8217;s because you have not set the user permission , please go to your  203.48.184.101 source and edit the permission ( i use phpmyadmin to make it easy ) go to mysql database -&gt; user tables -&gt; select the user -&gt; edit<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-173\" title=\"mysqlpriviledgespng\" src=\"http:\/\/adityo.blog.binusian.org\/files\/2009\/03\/mysqlpriviledgespng.png\" alt=\"mysqlpriviledgespng\" width=\"600\" height=\"891\" srcset=\"https:\/\/adityo.blog.binusian.org\/files\/2009\/03\/mysqlpriviledgespng.png 600w, https:\/\/adityo.blog.binusian.org\/files\/2009\/03\/mysqlpriviledgespng-202x300.png 202w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is MySQL ? MySQL is a relational database management system (RDBMS) based on SQL (Structured Query Language). First released in January, 1998, MySQL is now one component of parent company MySQL AB&#8217;s product line of database servers and development tools. MySQL version i assume you have installed mysql before, if not you can use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[491],"tags":[911],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql-db-connection-setting"],"_links":{"self":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=73"}],"version-history":[{"count":3,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":190,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions\/190"}],"wp:attachment":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}