Restricting MySQL connections from localhost to improve security

前端 未结 4 949
暖寄归人
暖寄归人 2020-12-29 03:42

I heard that anyone that knows my MySQL Username and Password can access it, Even if it\'s listening only to localhost.

Supposing my info is as following:

4条回答
  •  独厮守ぢ
    2020-12-29 04:19

    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
    

提交回复
热议问题