GRANT priv_set on dbname to username
字段名 | 含义 |
all | 允许用户获得 除 grant option 以外的所有权限 |
select | 允许用户获得查询记录的权限 |
insert | 允许用户获得插入记录的权限 |
update | 允许用户获得更新记录的权限 |
delete | 允许用户获得删除记录的权限 |
create user | 允许用户获得创建用户的权限 |
create view | 允许用户获得创建视图的权限 |
create table | 允许用户获得创建表的权限 |
drop | 删除表的权限 |
reload | 重新装载授权表的权限 |
shutdown | 重启数据库权限 |
process | 线程管理权限 |
file | 允许用户 SELECT...INTO OUTFILE 和 LOAD DATA INFILE |
grant option | 允许用户授予别人权限 |
references | 引用外键权限 |
index | 允许用户获得索引权限 |
alter routine | 允许用户获得更改或取消已存储的子程序 |
alter | 允许用户获得修改数据表的权限 |
process | 允许用户获得管理线程的权限 |
show view | 允许用户获得查看视图权限 |
show databases | 允许用户获得查看数据库的权限 |
super | 允许用户获得超级用户的权限 |
create temporary tables | 允许用户获得创建临时表的权限 |
look tables | 允许用户获得锁定数据表的权限 |
Execute | 执行用户获得执行存储过程的权限 |
replication slave | 设定复制主服务器的权限 |
replication client | 设定复制从服务器权限 |
usage | 无任何权限 |
mysql> create user 'beyes'@'localhost' identified by '123456';
mysql> show databases;
mysql> create database mydb;
ERROR 1044 (42000): Access denied for user 'beyes'@'localhost' to database 'mydb'
mysql> grant all privileges on *.* to 'beyes'@'localhost';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> create database mydb;
Query OK, 1 row affected (0.06 sec)
mysql> grant all privileges on *.* to 'beyes'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'beyes'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'temp'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> create database tempdb;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on *.* to 'temp2'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#创建一个 temp3 的用户,此时没有什么权限
mysql> create user 'temp3'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
#创建一个数据库
mysql> create database db_temp3;
Query OK, 1 row affected (0.62 sec)
#分配数据库级权限
mysql> grant all privileges on db_temp3.* to 'temp3'@'localhost';
Query OK, 0 rows affected (0.00 sec)
#刷新使生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#切换数据库
mysql> use db_temp3;
Database changed
#创建一个表
mysql> create table temp3_tb1 (Name varchar(50), age int);
Query OK, 0 rows affected (1.07 sec)
#插入记录操作
mysql> insert into temp3_tb1 values('groad.net', 3);
Query OK, 1 row affected (0.68 sec)
#错误:尝试创建数据库!!
mysql> create database temp3_new;
ERROR 1044 (42000): Access denied for user 'temp3'@'localhost' to database 'temp3_new'
mysql> grant select, insert, delete, update on db_temp3.temp3_tb1 to 'temp31'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> use db_temp3;
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
mysql> select * from temp3_tb1;
+-----------+------+
| Name | age |
+-----------+------+
| groad.net | 3 |
+-----------+------+
1 row in set (0.00 sec)
#错误:尝试删除表!!
mysql> drop table temp3_tb1;
ERROR 1142 (42000): DROP command denied to user 'temp31'@'localhost' for table 'temp3_tb1'
grant insert(columnname) on DB.TB to 'username'@'localhost' identified by 'new_user_password'
mysql> grant select(Name), insert(Name) on db_temp3.temp3_tb1 to 'temp4'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#切换数据库
mysql> use db_temp3;
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
#查看 temp3_tb1 表中的 Name 字段
mysql> select Name from temp3_tb1;
+-----------+
| Name |
+-----------+
| groad.net |
+-----------+
1 row in set (0.00 sec)
#错误:越权查看其它的字段
mysql> select * from temp3_tb1;
ERROR 1142 (42000): SELECT command denied to user 'temp4'@'localhost' for table 'temp3_tb1'
grant execute on procedure XXX.test_pro to 'temp'@'localhost'[/qutoe]
上面的语句含义是,用户 temp 获得数据库 XXX 中 test_pro 的执行权限。
如果是函数,那么 SQL 示意为:
[quote]grant execute on function on XXX.test_func to 'temp'@'localhost'
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |