Mysql权限整理及授权命令
1、创建用户
MariaDB [mysql]> create user test@'%' identified by '123456';
注意:test -> 新增的用户名,123456 -> 用户密码,%表示任何IP都可访问
2、用户授权
MariaDB [mysql]> grant select,insert,update,delete on *.* to test;
MariaDB [mysql]> flush privileges;
3、修改密码,同时允许远程登录
MariaDB [(none)]> use mysql;
MariaDB [mysql]> SET PASSWORD FOR 'test'@'%' = PASSWORD('123123');
MariaDB [mysql]> update user set password=password('123123') where user='test' and host='%';
MariaDB [mysql]> flush privileges;
注意:%表示任何IP都可访问
4、取消授权
revoke跟grant的语法差不多,只需要把关键字"to"换成"from"即可:
MariaDB [mysql]> revoke select on *.* from 'test'@'%';
MariaDB [mysql]> flush privileges;
5、删除用户
MariaDB [mysql]> drop user 'test'@'%';
MariaDB [mysql]> flush privileges;
6、查看用户权限
# 查看当前用户权限:
MariaDB [mysql]> show grants;
# 查看其它用户权限:
MariaDB [mysql]> show grants for 'test'@'%';