MySQL5.7的权限介绍
本篇内容介绍了“MySQL5.7的权限介绍”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
MySQL支持的权限如下:
ALL或ALL PRIVILEGES代表指定权限等级的所有权限。
ALTER允许使用ALTER TABLE来改变表的结构,ALTER TABLE同时也需要CREATE和INSERT权限。重命名一个表需要对旧表具有ALTER和DROP权限,对新版具有CREATE和INSERT权限。
ALTER ROUTINE允许改变和删除存储过程和函数
CREATE允许创建新的数据库和表
CREATE ROUTINE允许创建创建存储过程和包
CREATE TABLESPACE允许创建、更改和删除表空间和日志文件组
CREATE TEMPORARY TABLES允许创建临时表
CREATE USER允许更改、创建、删除、重命名用户和收回所有权限
CREATE VIEW允许创建视图
DELETE允许从数据库的表中删除行
DROP允许删除数据库、表和视图
EVENT允许在事件调度里面创建、更改、删除和查看事件
EXECUETE允许执行存储过程和包
FILE允许在服务器的主机上通过LOAD DATA INFILE、SELECT ... INTO OUTFILE和LOAD_FILE()函数读写文件
GRANT OPTION允许向其他用户授予或移除权限
INDEX允许创建和删除索引
INSERT允许向数据库的表中插入行
LOCK TABLE允许执行LOCK TABLES语句来锁定表
PROCESS允许显示在服务器上执行的线程信息,即被会话所执行的语句信息。这个权限允许你执行SHOW PROCESSLIST和mysqladminprocesslist命令来查看线程,同时这个权限也允许你执行SHOW ENGINE命令
PROXY允许用户冒充成为另外一个用户
REFERENCES允许创建外键
RELOAD允许使用FLUSH语句
REPLICATION CLIENT允许执行SHOW MASTER STATUS,SHOW SLAVE STATUS和SHOW BINARY LOGS命令
REPLICATION SLAVE允许SLAVE服务器连接到当前服务器来作为他们的主服务器
SELECT允许从数据库中查询表
SHOW DATABASES允许账户执行SHOW DATABASE语句来查看数据库。没有这个权限的账户只能看到他们具有权限的数据库。
SHOW VIEW允许执行SHOW CREATE VIEW语句
SHUTDOWN允许执行SHUTDOWN语句和mysqladmin shutdown已经mysql_shutdown() C API函数
SUPER允许用户执行CHANGE MASTER TO,KILL或mysqladmin kill命令来杀掉其他用户的线程,允许执行PURGE BINARY LOGS命令,通过SETGLOBAL来设置系统参数,执行mysqladmin debug命令,开启和关闭日志,即使read_only参数开启也可以执行update语句,打开和关闭从服务器上面的复制,允许在连接数达到max_connections的情况下连接到服务器。
TRIGGER允许操作触发器
UPDATE允许更新数据库中的表
USAGE代表没有任何权限
授予全局权限:
*.*代表所有数据库的权限
mysql> grant all on *.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select, insert on *.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
授予指定数据库的权限:
mysql> grant all on test.* to 'test'@'localhost';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> grant select, insert on *.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select, insert on test.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
授予指定表的权限:
mysql> grant all on test.orders to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.13 sec)
mysql> grant select, insert on test.orders to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.07 sec)
授予指定字段的权限:
mysql> desc test.orders_1;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| order_date | date | YES | | NULL | |
| order_id | int(11) | YES | | NULL | |
| customer_name | varchar(15) | YES | | NULL | |
| product_id | int(11) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> grant select(order_date), insert(order_id,customer_name) on test.orders_1 to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.01 sec)
[root@T400-kelong ~]# mysql -ujeffrey -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.10-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test;
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 orders_1;
ERROR 1142 (42000): SELECT command denied to user 'jeffrey'@'localhost' for table 'orders_1'
mysql> select order_date from orders_1;
+------------+
| order_date |
+------------+
| 2016-03-26 |
+------------+
1 row in set (0.00 sec)
授予存储过程的权限:
mysql> grant create routine on test.* to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.08 sec)
mysql> grant execute on procedure test.myproc to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.04 sec)
授予代理用户权限:
PROX权限可以使一个用户成为另外一个用户的代理
mysql> grant proxy on 'jeffrey'@'localhost' to 'test'@'%';
Query OK, 0 rows affected (0.09 sec)
“MySQL5.7的权限介绍”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。