用户操作
创建用户
create user sky@'10.0.0.%' identified by '123';
8.0之前,可以自动创建用户并授权
grant all on *.* to sky@'10.0.0.%' identified by '123';
查询用户
select user,host from mysql.user;
修改用户密码
alter user sky@'10.0.0.%' identified by '123456';
删除用户
drop user sky@'10.0.0.%' ;
权限的管理
权限的列表
ALL
SELECT,INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE
授权的命令
grant 权限 on 作用目标 to 用户 identified by 密码 with grant option;
grant all on *.* to sky@'10.0.0.%' identified by '123';
作用目标:
. 所有库下的所有表
sky.* 某一个库(sky库)下所有表
sky.t1 sky库下t1表
创建一个管理员用户,可以通过10网段,管理数据库
grant all on *.* to root@'10.0.0.%' identified by '123' with grant option;
创建一个应用用户,可以通过10网段,wordpress库下的所有表
grant select,insert,update,delete on wordpress@'10.0.0.%' identified by '123' with grant option;
查看用户的权限
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.%' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
回收用户的权限
mysql> revoke delete on wordpress.* from wordpress@'10.0.0.%';
生产中开通用户
(1)如何沟通开用户
1.是否有邮件批复
2.对那些库和表做操作
3.做什么操作
4.从什么地址登陆