How to grant remote access to MySQL for a whole subnet?

前端 未结 7 1763
不知归路
不知归路 2020-12-02 07:50

I can easily grant access to one IP using this code:

$ mysql -u root -p
Enter password:    
mysql> use mysql    
mysql> GRANT ALL ON *.* to root@\'192.         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 08:24

    EDIT: Consider looking at and upvoting Malvineous's answer on this page. Netmasks are a much more elegant solution.


    Simply use a percent sign as a wildcard in the IP address.

    From http://dev.mysql.com/doc/refman/5.1/en/grant.html

    You can specify wildcards in the host name. For example, user_name@'%.example.com' applies to user_name for any host in the example.com domain, and user_name@'192.168.1.%' applies to user_name for any host in the 192.168.1 class C subnet.

提交回复
热议问题