{"id":373,"date":"2020-08-30T22:26:51","date_gmt":"2020-08-31T03:26:51","guid":{"rendered":"https:\/\/horazmakes.com\/blog\/?p=373"},"modified":"2020-08-30T22:26:51","modified_gmt":"2020-08-31T03:26:51","slug":"change-connecting-host-for-mysql-database","status":"publish","type":"post","link":"https:\/\/horazmakes.com\/blog\/2020\/08\/30\/change-connecting-host-for-mysql-database\/","title":{"rendered":"Change connecting host for MySQL database"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>In MySQL, you can configure the host(s) from which your database allows connections. This is an important security feature at connection level.<\/p>\n\n\n\n<p>In this post, you can see how to review the current configuration of your MySQL database and how to change it. The following procedures were successfully tested in <strong>MySQL 8.0.21<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Check your current configuration<\/h2>\n\n\n\n<p>The information regarding the connecting hosts lives in two different tables:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>mysql.user<\/li><li>mysql.db<\/li><\/ul>\n\n\n\n<p>You can use the following queries to find out the current state of your configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT host, user FROM mysql.user;<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT Host, Db, User FROM mysql.db;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Change your configuration<\/h2>\n\n\n\n<p>In order to change your host configuration, you can update directly both tables, mysql.user and mysql.db. Finally, go ahead and flush privileges.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> UPDATE mysql.user SET host = 'localhost' WHERE host = '%' AND user = 'username';<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">UPDATE mysql.db SET Host = 'localhost' WHERE Host = '%' AND User = 'username';<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">FLUSH PRIVILEGES;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In MySQL, you can configure the host(s) from which your database allows connections. This is an important security feature at connection level. In this post, you can see how to review the current configuration of your MySQL database and how to change it. The following procedures were successfully tested in MySQL 8.0.21 Check your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":257,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,86],"tags":[140,139,138,104,87,142,141],"class_list":["post-373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","category-programming","tag-configuration","tag-connecting-host","tag-host","tag-localhost","tag-mysql","tag-mysql-security","tag-security"],"_links":{"self":[{"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/posts\/373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/comments?post=373"}],"version-history":[{"count":3,"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/posts\/373\/revisions"}],"predecessor-version":[{"id":376,"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/posts\/373\/revisions\/376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/media\/257"}],"wp:attachment":[{"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/media?parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/categories?post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/horazmakes.com\/blog\/wp-json\/wp\/v2\/tags?post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}