mysql里面用户赋权,grant授权和user表修改,哪个优先级高?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql里面用户赋权,grant授权和user表修改,哪个优先级高?相关的知识,希望对你有一定的参考价值。

mysql里面用户赋权,通过grant all privileges on db.* to ‘user’@'192.168.1.2' identified by 123123 授权,修改user表里面的host值,哪个优先级高?

参考技术A 可见,其中的Host,User,Password就是我们登录时候需要输入的参数,列名为*_priv的列对应的是增、删、改、建表、删表、、、等权限。追问

我是问这两种方式,哪个好?哪个优先级高?你这回答的我都看不懂你想说啥呀!

mysql创建用户以及授权

默认用户有root超级管理员,要做一个网站,要连接mysql要一个用户名和密码,不可能是root,防止误操作。Mysql服务里面可以跑多个库,所以需要给单独的用户作一些授权,只需要他对某一个数据库或者某个数据库的某个表有权限。

grant all on . to ‘user1‘ identified by ‘passwd‘; // grant是授权的意思 all全部的
1.mysql> grant all on . to ‘user1‘@‘127.0.0.1‘ identified by ‘123‘; //授权user1只能通过127这个ip登录mysql(源ip) identified by密码 .前面这个表示库名,后面是表。Ip也可以使用%表示所有的ip,
Query OK, 0 rows affected (0.63 sec)
2.[[email protected] ~]# mysql -uuser1 -p123 -h127.0.0.1 //用户登录。如果授权ip是localhost那么可以不用-h

3.mysql> grant all on db1.* to ‘user1‘@‘192.168.222.%‘ identified by ‘1‘;
4.[[email protected] ~]# mysql -uuser1 -p1 -h192.168.222.51

5.grant SELECT,UPDATE,INSERT on db1. to ‘user2‘@‘192.168.133.1‘ identified by ‘passwd‘;
6.grant all on db1.
to ‘user3‘@‘%‘ identified by ‘passwd‘;

7.show grants;//查看当前用户的授权
mysql> show grants; //查看权限必须进入要查询的用户里面
+-------------------------------------------------------------------------------+
| Grants for [email protected]% |
+-------------------------------------------------------------------------------+
| GRANT USAGE ON . TO ‘user1‘@‘192.168.222.%‘ IDENTIFIED BY PASSWORD <secret> |
| GRANT ALL PRIVILEGES ON db1.* TO ‘user1‘@‘192.168.222.%‘ |
+-------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> select user();
+----------------------+
| user() |
+----------------------+
| [email protected] |
+----------------------+
1 row in set (0.00 sec)

8.show grants for [email protected]; //查看指定用户的授权
mysql> select user();
+----------------+
| user() |
+----------------+
| [email protected] |
+----------------+
1 row in set (0.00 sec)

mysql> grant SELECT,UPDATE,INSERT on db1.* to ‘user3‘@‘192.168.222.%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for [email protected]‘192.168.222.%‘;
+------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]% |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON . TO ‘user3‘@‘192.168.222.%‘ IDENTIFIED BY PASSWORD ‘6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘ |
| GRANT SELECT, INSERT, UPDATE ON db1.
TO ‘user3‘@‘192.168.222.%‘ |
+------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

以上是关于mysql里面用户赋权,grant授权和user表修改,哪个优先级高?的主要内容,如果未能解决你的问题,请参考以下文章

oracle的grant语句,一次只能授权一张表的访问权限吗?

MySQL:grant 语法详解(MySQL5.X)

求助,MySql 5.6.17 授权用户问题

mysql创建用户以及授权

怎么给oracle数据库创建用户,并赋权限

Day906.grant语句 -MySQL实战