MariaDB [(none)]> show grants for lyshark; +----------------------------------------------+ | Grants for lyshark@% | +----------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'lyshark'@'%' | +----------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]>
查询指定权限: 查询lyshark用户的远程%权限,和本地localhost权限
MariaDB [(none)]> show grants for"lyshark"@"%"; +----------------------------------------------+ | Grants for lyshark@% | +----------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'lyshark'@'%' | +----------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]> show grants for"lyshark"@"localhost"; +----------------------------------------------------------------------------------------------------------------+ | Grants for lyshark@localhost | +----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'lyshark'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | +----------------------------------------------------------------------------------------------------------------+ 1 row inset (0.37 sec)
MariaDB [(none)]>
◆授予权限◆
创建用户并授权: 创建wang用户并给予%远程登陆的权限,并对所有数据库全部授权
MariaDB [(none)]> grant all on *.* to "wang"@"%" identified by "123"; Query OK, 0 rows affected (0.15 sec)
MariaDB [(none)]> show grants for"wang"@"%"; +--------------------------------------------------------------------------------------------------------------+ | Grants for wang@% | +--------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'wang'@'%' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | +--------------------------------------------------------------------------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]> grant select on mysql.* to "wang1"@"localhost" identified by "123"; Query OK, 0 rows affected (0.36 sec)
MariaDB [(none)]> show grants for"wang1"@"localhost"; +--------------------------------------------------------------------------------------------------------------+ | Grants for wang1@localhost | +--------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'wang1'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | | GRANT SELECT ON `mysql`.* TO 'wang1'@'localhost' | +--------------------------------------------------------------------------------------------------------------+ 2 rows inset (0.00 sec)
MariaDB [(none)]> grant select on mysql.* to "wang3"@"192.168.1.59" identified by "123"; Query OK, 0 rows affected (0.15 sec)
MariaDB [(none)]> show grants for"wang3"@"192.168.1.59"; +-----------------------------------------------------------------------------------------------------------------+ | Grants for wang3@192.168.1.59 | +-----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'wang3'@'192.168.1.59' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | | GRANT SELECT ON `mysql`.* TO 'wang3'@'192.168.1.59' | +-----------------------------------------------------------------------------------------------------------------+ 2 rows inset (0.50 sec)
MariaDB [(none)]>
创建用户并授权: 创建一个普通用户wang4,且仅有mysql库的(查)权限,密码为123
MariaDB [(none)]> grant usage,select on mysql.* to "wang4"@"localhost" identified by "123"; Query OK, 0 rows affected (0.35 sec)
只授权用户权限: 授权用户wang4,对所有数据库的全部权限,密码123
MariaDB [(none)]> grant all privileges on *.* to "wang4"@"localhost" identified by "123"; Query OK, 0 rows affected (0.36 sec)
只授权用户权限: 授权一个已存在账号允许远程登陆最大权限
MariaDB [(none)]> grant all on *.* to "root"@"%"; Query OK, 0 rows affected (0.07 sec)
◆收回权限◆
收回用户授权: 撤销lyshark用户,对所有数据库的远程%用户权限
MariaDB [(none)]> show grants for lyshark; +----------------------------------------------+ | Grants for lyshark@% | +----------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'lyshark'@'%' | +----------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]> revoke all on *.* from "lyshark"@"%"; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show grants for lyshark; +-------------------------------------+ | Grants for lyshark@% | +-------------------------------------+ | GRANT USAGE ON *.* TO 'lyshark'@'%' | +-------------------------------------+ 1 row inset (0.00 sec)
收回用户授权: 撤销lyshark用户的远程登陆权限
MariaDB [(none)]> revoke create on *.* from "lyshark"@"%"; Query OK, 0 rows affected (0.01 sec)