test账户可以从任意IP连接
create user 'test'@'%' identified by '***';
test账户只能从本地连接
create user 'test'@'localhost' identified by '***';
test账户只能从'192.168.2.%'网段连接
create user 'test'@'192.168.2.%' identified by '***';
还可以使用IP掩码
create user 'test'@'192.168.2.2
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*578EC7851088AC1F2A67B100540344B03BD2BA99' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
也可以通过show grants for 获得其它用户的权限:
mysql>show grants for ''@'localhost';
+--------------------------------------+
| Grants for @localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
上面显示的是两种特殊权限,一种是ALL(后面的PRIVILEGES关键字可省略),表示所有操作的权限(但不包括Grant权限,Grant权限由with grant option赋予);另一种是USAGE,一种特殊的“无权限”的权限。