用户和权限管理
基于mariadb测试
创建用户,用户没有创建数据库和数据表等权限,只有查看information_schema数据库权限。参考 https://mariadb.com/kb/en/create-user/
create user test1@localhost identified by 'test';创建或者替换用户,如果用户已经存在不会报告错误。
create or replace user test1@localhost identified by 'test';如果用户存在就提示警告
create user if not exists test1@localhost identified by 'test';重命名用户,如果不指定host部分则默认使用%。
# test1@'localhost'用户被修改为test11@'%'
rename user test1@'localhost' to test11;
# test11@'%'用户被修改为test1@'localhost'
rename user test11@'%' to test1@'localhost';删除用户
drop user test1@'localhost';
# 如果用户不存在只会提示警告
drop user if exists test1@'localhost';修改用户密码,参考 https://mariadb.com/kb/en/set-password/
set password for test1@localhost = password("12345678");使用alter user修改用户密码,参考 https://mariadb.com/kb/en/alter-user/
alter user test1@localhost identified by 'test';权限管理
注意: 使用mariadb:11.3.2测试,使用mariadb:10.4.19有些权限不存在导致grant语法错误。
显示指定用户当前已经分配的权限
show grants for test1@localhost;回收指定用户的指定权限
# 创建用户
create user if not exists user1@'%' identified by '123456';
# 授予所有权限
grant all privileges on *.* to user1@'%';
# 回收其中的super权限
revoke super on *.* from user1@'%';全局权限
binlog admin权限
启用二进制日志的管理,包括 PURGE BINARY LOGS 语句和设置相关binlog系统变量
参考 https://mariadb.com/kb/en/grant/#binlog-admin
grant binlog admin on *.* to test1@localhost;binlog monitor权限
MariaDB 10.5.2 中 REPLICATION CLIENT 的新名称(出于兼容性目的,仍支持将 REPLICATION CLIENT 作为别名)。 允许运行与二进制日志相关的 SHOW 命令,特别是 SHOW BINLOG STATUS 和 SHOW BINARY LOGS 语句。 与 MariaDB 10.5 之前的 REPLICATION CLIENT 不同,此权限不包含 SHOW REPLICA STATUS,并且需要 REPLICA MONITOR。
参考 https://mariadb.com/kb/en/grant/#binlog-monitor
grant binlog monitor on *.* to test1@localhost;binlog replay权限
允许使用 BINLOG 语句(由 mariadb-binlog 生成)重放二进制日志,在 secure_timestamp 设置为复制时执行 SET 时间戳,并设置通常包含在 BINLOG 输出中的系统变量的会话值。
参考 https://mariadb.com/kb/en/grant/#binlog-replay
grant binlog replay on *.* to test1@localhost;shutdown权限
使用 SHUTDOWN 或 mariadb-admin shutdown 命令关闭服务器。
参考 https://mariadb.com/kb/en/grant/#shutdown
grant shutdown on *.* to test1@localhost;