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;