微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mariadb数据库用户管理创建、赋权、

数据库查看当前用户 select user();

MariaDB [(none)]> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

数据库新建用户 (--创建了一个名为:test 密码为:1234 的用户

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

 

查询用户

MariaDB [zabbix]> select user,host from MysqL.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| root   | 127.0.0.1 |
| root   | ::1       |
| root   | localhost |
| test   | localhost |
| zabbix | localhost |
+--------+-----------+
5 rows in set (0.00 sec)

修改用户密码

方法1,密码实时更新;修改用户“test”的密码为“5678”

MariaDB [MysqL]> set password for test@localhost =password('5678');                                     
Query OK, 0 rows affected (0.00 sec)

MariaDB [MysqL]> exit
Bye

[root@192 ~]# MysqL -utest -p5678
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 271
Server version: 10.2.36-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)]> select user();
+----------------+
| user() |
+----------------+
| test@localhost |
+----------------+
1 row in set (0.00 sec)

 方法2 ,需要刷新;修改用户“test”的密码为“1234”

MariaDB [(none)]> update MysqL.user set password =password('root') where user='test';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [(none)]> flush privileges;  刷新权限
Query OK, 0 rows affected (0.00 sec)

  方法3,命令行修改  MysqLadmin -u用户名 -p旧密码 password 新密码

[root@192 ~]# MysqLadmin -uroot -p1 password root
[root@192 ~]# MysqL -uroot -proot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 95
Server version: 10.2.36-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)]> 

分配用户权限

授予用户test通过外网IP对所有数据库所有表的全部权限

MariaDB [(none)]> grant all privileges on *.* to 'test'@'%' identified by '1234'; 
Query OK, 0 rows affected (0.00 sec)

 注意:修改完权限以后 一定要刷新服务,或者重启服务,刷新服务用:flush privileges; 

查看用户权限 show grants for test;

MariaDB [(none)]> show grants for test;
+--------------------------------------------------------------------------------------------------------------+
| Grants for test@%                                                                                            |
+--------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' |
+--------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

  

删除用户 drop user test;

MariaDB [(none)]> drop user test;
Query OK, 0 rows affected (0.00 sec)

  

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐