1、用户的管理(增、删、改、查) create user yu0l@'10.0.0.%' identified by '123456'; #创建用户 grant all on *.* to yu0l1@'10.0.0.%' identified by '123456'; #8.0版本以前可以授权时创建用户 mysql> create user yu0l@'10.0.0.%' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> grant all on *.* to yu0l1@'10.0.0.%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> select user,host from mysql.user; #查询用户 +---------------+-----------+ | user | host | +---------------+-----------+ | yu0l | 10.0.0.% | | yu0l1 | 10.0.0.% | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+
alter user yu0l@'10.0.0.%' identified by '654321'; #修改用户密码 mysql> drop user yu0l@'10.0.0.%'; #删除用户 Query OK, 0 rows affected (0.00 sec)
1
2、权限管理
权限列表
1 2 3 4
授权命令 # grant 权限 on 作用目标 to 用户 identified by 密码 with grant option; #权限:All+with grant option(给其他用户授权) = root;可以是单个权限(如select)或所有(all) #作用目标:*.*(所有) wordpress.*(wordpress仅这个库) wordpress.t1(仅这个表)
grant all on *.* to root@'10.0.0.%' identified by '123456'; grant SELECT,UPDATE,INSERT,DELETE on wordpress.* to wordpress@'10.0.0.%' identified by '654321';
回收权限 show grants for wordpress@'10.0.0.%'; #查询用户权限 revoke delete on wordpress.* from wordpress@'10.0.0.%'; #回收DELETE的权限 mysql> show grants for wordpress@'10.0.0.%'; +---------------------------------------------------------------------------------+ | Grants for wordpress@10.0.0.% | +---------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'wordpress'@'10.0.0.%' | | GRANT SELECT, INSERT, UPDATE, DELETE ON `wordpress`.* TO 'wordpress'@'10.0.0.%' | +---------------------------------------------------------------------------------+ mysql> revoke delete on wordpress.* from wordpress@'10.0.0.%'; Query OK, 0 rows affected (0.00 sec) mysql> show grants for wordpress@'10.0.0.%'; +-------------------------------------------------------------------------+ | Grants for wordpress@10.0.0.% | +-------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'wordpress'@'10.0.0.%' | | GRANT SELECT, INSERT, UPDATE ON `wordpress`.* TO 'wordpress'@'10.0.0.%' | +-------------------------------------------------------------------------+ #DELETE的权限没有了