10.2管理用户以及授权

1.创建数据库管理用户

MariaDB [mysql]> SELECT HOST,USER,PASSWORD FROM user WHERE USER="dsrw";
+-----------+------+-------------------------------------------+
| HOST      | USER | PASSWORD                                  |
+-----------+------+-------------------------------------------+
| localhost | dsrw | *7BAFEDD34C3DDD2AFCA6BF0F9695F2B0A1E9891C |
+-----------+------+-------------------------------------------+
1 row in set (0.000 sec)

2.使用dsrw用户登录数据库

[root@dsrw ~]# mysql -u dsrw -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
显示数据库
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.000 sec)

以root管理员的身份登录到数据库管理系统中,针对mysql数据库中的user表单向用户dsrw授予查询、更新、删除以及插入等权限。
MariaDB [(none)]> exit
Bye
[root@dsrw ~]# mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> USE  mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

1)给dsrw用户授权

MariaDB [mysql]> GRANT SELECT,UPDATE,DELETE,INSERT ON mysql.user TO dsrw@localhost;
Query OK, 0 rows affected (0.000 sec)
MariaDB [mysql]> SHOW GRANTS FOR dsrw@localhost;
+-------------------------------------------------------------------------------------------------------------+
| Grants for dsrw@localhost                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'dsrw'@'localhost' IDENTIFIED BY PASSWORD '*7BAFEDD34C3DDD2AFCA6BF0F9695F2B0A1E9891C' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.`user` TO 'dsrw'@'localhost'                                |
+-------------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)

MariaDB [mysql]> exit
Bye
[root@dsrw ~]# mysql -u dsrw -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]> exit
Bye
[root@dsrw ~]# mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 25
Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2)取消dsrw用户授权

MariaDB [(none)]> REVOKE SELECT,UPDATE,DELETE,INSERT ON mysql.user FROM dsrw@localhost;
Query OK, 0 rows affected (0.000 sec)

3)删除用户

MariaDB [(none)]> DROP user dsrw@localhost;
Query OK, 0 rows affected (0.000 sec)
© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称

    请登录后查看评论内容