MySQL

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 current configuration

The information regarding the connecting hosts lives in two different tables:

  • mysql.user
  • mysql.db

You can use the following queries to find out the current state of your configuration:

SELECT host, user FROM mysql.user;
SELECT Host, Db, User FROM mysql.db;

Change your configuration

In order to change your host configuration, you can update directly both tables, mysql.user and mysql.db. Finally, go ahead and flush privileges.

 UPDATE mysql.user SET host = 'localhost' WHERE host = '%' AND user = 'username';
UPDATE mysql.db SET Host = 'localhost' WHERE Host = '%' AND User = 'username';
FLUSH PRIVILEGES;

By horaz

Hello, my name is Horacio Conde, Vic’s proud father, an apprentice maker and a computer science engineer. I live in Mexico City and I’ve been working professionally in software development for more than fifteen years now. I’m very interested in technologies such as programming, The Internet of Things (IoT) (Arduino, Raspberry Pi), electronics, physical computing, automation, woodworking.

Leave a Reply

Your email address will not be published. Required fields are marked *