How To Disable Remote Access in MySQL Database

This guide will show you how to Disable Remote Access in MySQL Database. Connecting remotely to a MySQL database, especially the root user, has many security issues. So we decided to show you to disable the remote access for root and all the users.

Follow the steps below to complete this guide.

How To Disable Remote Access in MySQL Database?

By default, remote access to your MySQL database must be disabled for security reasons. But if you have changed this setting, you can follow the steps below to disable it for root and all the users.

Step 1 – Prevent MySQL Database Remote Access for Root User

First, you must connect to your MySQL shell and access your desired database.

Then, enter the following MySQL command to delete all the records in mysql.user table, where your user is the root and the host is localhost, 127.0.0.0.1, and ::1:

DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');

Finally, flush the privileges to apply the changes:

FLUSH PRIVILEGES;

Exit from your MySQL shell:

EXIT;

Step 2 – Prevent MySQL Database Remote Access for All Users

If you plan to disable the all remote connection, you must edit the my.ini or my.cnf files. It depends on the platform it is installed.

Note: To get information about MySQL config file, you can visit this guide on Find MySQL Configuration File Location on Linux.

When you have opened your file, you can use any text editor like vi editor, seachfor the [mysqld] section. Add the follwoing line under [mysqld] section:

[mysqld]
...
skip-networking
...

Or if it is exists, uncomment it. With this option, you disabled the MySQL remote connection for all users.

When you are done, save and close the file.

That’s it you are done.

Conclusion

At this point, you have learned to Disable Remote Access in MySQL Database for both root and all the users. This option is diabled by default for security reasons, but if you have change this setting, you can easily disable it.

Hope you enjoy it. You may be intrested in these articles:

Enable Remote Connections For MySQL on Centos 7

How To Create a New User on MySQL

Change MySQL settings on DirectAdmin from Admin panel

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!
Latest Articles

POPULAR TAGS

Most Popular