侧边栏壁纸
博主头像
一揽芳华 博主等级

行动起来,活在当下

  • 累计撰写 265 篇文章
  • 累计创建 24 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

13.4、管理账户以及授权

芳华是个男孩!
2024-10-14 / 0 评论 / 0 点赞 / 10 阅读 / 0 字
广告 广告

title: 04-管理账户和授权
order: 4

icon: lightbulb

为了保证数据库系统的安全性,以及让其他用户协同管理数据库,我们可以在mariadb数据库管理 系统中创建多个用户,并分配相关权限,满足工作需求。

1、认识常用权限

2、新建用户,命令格式: create user 用户名@主机名 identified by'密码' ;示例:新建用户 zxw ,密码 为: 0000

MariaDB [(none)]> create user zxw@localhost identified by '0000'; Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

用新建的用户测试登录:

返回到root登录使用命令select查看用户:

MariaDB [(none)]> use mysql

MariaDB [mysql]> select host,user,password from user where user='zxw';

新建的用户zxw没有任何数据库操作权限,我们可以使用管理员root赋予zxw用户权限,以完成相关操 作

3、针对mysql数据库中的user表单向账户zxw授予查询、更新、删除以及插入等权限,使用命令grant

MariaDB [mysql]> grant select,update,delete,insert on mysql.user to zxw@localhost;

4、查看账户zxw的权限

MariaDB [(none)]> show grants for zxw@localhost;

5、切换至zxw用户下,查看mysql数据库,而且还能看到表单user (其余表单会因为没有权限而被继续 隐藏)

MariaDB [(none)]> show databases;

MariaDB [(none)]> use mysql;

MariaDB [mysql]> show tables;

5、返回到root管理员用户下,使用命令revoke移除相关权限

MariaDB [(none)]> revoke select,update,delete,insert on mysql.user from zxw@localhost;

6、在次查看zxw用户权限

MariaDB [(none)]> show grants for zxw@localhost;

7、使用seletc命令查看所有用户

MariaDB [(none)]> select user,host,password from mysql.user;

8、删除zxw用户

MariaDB [(none)]> use mysql;

MariaDB [mysql]> delete from user where user='zxw';

9、再次查看所有用户

MariaDB [mysql]> select user,host,password from mysql.user;

此时我们发现库中已经没有zxw这个用户了

0
广告 广告

评论区