mysql allow only local connections code example

Example: mysql allow only local connections

If you restrict access from remote hosts to your usernames and passwords then someone won't be able to access the database externally.

You could also configure your firewall to only allow traffic to 3306 (MySQL Default Port) from the localhost machine.

Update

To setup your user so they can only access through LOCALHOST use:

GRANT ALL PRIVILEGES ON *.* TO db_user @'localhost' IDENTIFIED BY 'db_passwd';
GRANT ALL PRIVILEGES ON *.* TO db_user @'127.0.0.1' IDENTIFIED BY 'db_passwd';
Also, bind your MySQL server to the local address. You can do this by editing the [mysqld] section of my.cnf:

[mysqld]
bind-address = 127.0.0.1

Tags:

Sql Example