{"id":6137,"date":"2015-03-31T01:45:59","date_gmt":"2015-03-30T17:45:59","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=6137"},"modified":"2023-04-28T09:47:16","modified_gmt":"2023-04-28T09:47:16","slug":"how-to-enable-and-grant-remote-access-to-mysql-database-server","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-enable-and-grant-remote-access-to-mysql-database-server\/","title":{"rendered":"How to Enable and Grant Remote Access to MySQL Database Server"},"content":{"rendered":"<p>For reasons of security, remote access to MySQL database server is disabled by default because they are considered potential security threats. However, due to some reason, it is necessary to allow access from a remote location or web server. Let assume that we are making connection from remote web server IP called <strong>192.168.0.3<\/strong> for database called <strong>db1<\/strong> for user <strong>user1<\/strong> at remote MySQL server, <strong>192.168.0.2<\/strong>, then we need to grant access to this IP address.<\/p>\n<p>If the remote access is not enable you will get this error :<\/p>\n<pre>ERROR 1130 (HY000): Host \u2018192.168.0.3\u2019 is not allowed to connect to this MySQL server\n<\/pre>\n<p><strong>IP Adress 1 : 192.168.0.2 &#8211; MySQL Server<br \/>\nIP Adress 2 : 192.168.0.3 &#8211; Web Server (Nginx or Apache)<\/strong><\/p>\n<p><h7>Steps to Enable and Grant Remote Access to MySQL Database Server<\/h7><\/p>\n<p>1. Edit the my.cnf file :<\/p>\n<pre># vim \/etc\/mysql\/my.cnf\n<\/pre>\n<p>Comment out or remove below line :<\/p>\n<pre>#bind-address           = 127.0.0.1\n<\/pre>\n<p>2. The following command will allow access to the MySQL database(192.168.0.2) from a remote web server IP address(192.168.0.3):<\/p>\n<pre>mysql&gt; create user 'user1'@'192.168.0.3' identified by 'PASSWORD';\nmysql&gt; grant all on db1.* to 'user1'@'192.168.0.3';\n<\/pre>\n<p>3. Test the connection from the remote web server :<\/p>\n<pre># mysql -u user1 -pPASSWORD -h 192.168.0.2\n<\/pre>\n<p>4. Verify the user privileges for user1 :<\/p>\n<pre>mysql&gt; select * from information_schema.user_privileges where grantee like \"'user1'%\";\n<\/pre>\n<p>5. In case you want to revoke all options the access from all machine or web server(192.168.0.3) only :<\/p>\n<pre>mysql&gt; revoke all privileges, grant option from 'user1'@'%';\n<\/pre>\n<pre>mysql&gt; revoke all privileges, grant option from 'user1'@'192.168.0.3';\n<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-6147 lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/03\/database.jpg\" alt=\"database\" width=\"598\" height=\"352\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/03\/database.jpg 598w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/03\/database-300x177.jpg 300w\" data-sizes=\"(max-width: 598px) 100vw, 598px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 598px; --smush-placeholder-aspect-ratio: 598\/352;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For reasons of security, remote access to MySQL database server is disabled by default because they are considered potential security threats. However, due to some reason, it is necessary to&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6184,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1006,1008],"tags":[1565,1585],"class_list":["post-6137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mariadb","category-mysql","tag-mariadb","tag-mysql"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=6137"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6137\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6184"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=6137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=6137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=6137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}