MySQL Crash Course #20# Chapter 28. Managing Security
限制用户的操作权限并不是怕有人恶意搞破坏,而是为了减少失误操作的可能性。
详细文档:https://dev.mysql.com/doc/refman/8.0/en/user-account-management.html
关于用户的信息都存储在 mysql 数据库下的 user 表中,查看所有用户名:
mysql> USE mysql; mysql> SELECT user FROM user;
+------------------+
| user |
+------------------+
| root |
| root |
| root |
| debian-sys-maint |
| root |
+------------------+
5 rows in set (0.04 sec)
创建新用户:
CREATE USER 'new_guy'@'localhost' IDENTIFIED BY '';
-- 创建一个叫 new_guy 的账号,只允许在 localhost 登陆,密码为 123456
明文密码会被加密为 HASH 码存储到 user 表中:
mysql> SELECT host, user, password FROM user WHERE user='new_guy'; +-----------+---------+-------------------------------------------+
| host | user | password |
+-----------+---------+-------------------------------------------+
| localhost | new_guy | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+---------+-------------------------------------------+
1 row in set (0.00 sec)
可以通过下面的语句查看用户的详细信息:
SELECT * FROM user WHERE user='new_guy'\G
没有被赋予任何权限的新用户几乎是什么都做不了:
-- 授权
GRANT SELECT ON mysqlCrash.* TO 'new_guy'@'localhost';
-- 剥夺权限
REVOKE SELECT ON mysqlCrash.* FROM 'new_guy'@'localhost';
-- 查看用户权限
SHOW GRANTS FOR 'new_guy'@'localhost';
GRANT and REVOKE can be used to control access at several levels:
Entire server, using GRANT ALL and REVOKE ALL
Entire database, using ON database.*
Specific tables, using ON database.table
Specific columns
Specific stored procedures
Table 28.1 lists each of the rights and privileges that may be granted or revoked.
Table 28.1. Rights and Privileges
|
Privilege |
Description |
|---|---|
|
ALL |
All privileges except GRANT OPTION |
|
ALTER |
Use of ALTER TABLE |
|
ALTER ROUTINE |
Use of ALTER PROCEDURE and DROP PROCEDURE |
|
CREATE |
Use of CREATE TABLE |
|
CREATE ROUTINE |
Use of CREATE PROCEDURE |
|
CREATE TEMPORARY TABLES |
Use of CREATE TEMPORARY TABLE |
|
CREATE USER |
Use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES |
|
CREATE VIEW |
Use of CREATE VIEW |
|
DELETE |
Use of DELETE |
|
DROP |
Use of DROP TABLE |
|
EXECUTE |
Use of CALL and stored procedures |
|
FILE |
Use of SELECT INTO OUTFILE and LOAD DATA INFILE |
|
GRANT OPTION |
Use of GRANT and REVOKE |
|
INDEX |
Use of CREATE INDEX and DROP INDEX |
|
INSERT |
Use of INSERT |
|
LOCK TABLES |
Use of LOCK TABLES |
|
PROCESS |
Use of SHOW FULL PROCESSLIST |
|
RELOAD |
Use of FLUSH |
|
REPLICATION CLIENT |
Access to location of servers |
|
REPLICATION SLAVE |
Used by replication slaves |
|
SELECT |
Use of SELECT |
|
SHOW DATABASES |
Use of SHOW DATABASES |
|
SHOW VIEW |
Use of SHOW CREATE VIEW |
|
SHUTDOWN |
Use of mysqladmin shutdown (used to shut down MySQL) |
|
SUPER |
Use of CHANGE MASTER, KILL, LOGS, PURGE MASTER, and SET GLOBAL. Also allows mysqladmin debug login. |
|
UPDATE |
Use of UPDATE |
|
USAGE |
No access |
删除用户用 DROP USER xxx 就可以了。
更多杂七杂八的操作,请参考 MySQL 8.0 Reference Manual / Security / MySQL User Account Management / Using Roles
MySQL Crash Course #20# Chapter 28. Managing Security的更多相关文章
- MySQL Crash Course #18# Chapter 26. Managing Transaction Processing
InnoDB 支持 transaction ,MyISAM 不支持. 索引: Changing the Default Commit Behavior SAVEPOINT 与 ROLLBACK TO ...
- MySQL Crash Course #11# Chapter 20. Updating and Deleting Data
INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Dele ...
- MySQL Crash Course #13# Chapter 21. Creating and Manipulating Tables
之前 manipulate 表里的数据,现在则是 manipulate 表本身. INDEX 创建多列构成的主键 自动增长的规定 查看上一次插入的自增 id 尽量用默认值替代 NULL 外键不可以跨引 ...
- MySQL Crash Course #10# Chapter 19. Inserting Data
INDEX BAD EXAMPLE Improving Overall Performance Inserting Multiple Rows INSTEAD OF Inserting a Singl ...
- MySQL Crash Course #06# Chapter 13. 14 GROUP BY. 子查询
索引 理解 GROUP BY 过滤数据 vs. 过滤分组 GROUP BY 与 ORDER BY 之不成文的规定 子查询 vs. 联表查询 相关子查询和不相关子查询. 增量构造复杂查询 Always ...
- MySQL Crash Course #04# Chapter 7. 8 AND. OR. IN. NOT. LIKE
索引 AND. OR 运算顺序 IN Operator VS. OR NOT 在 MySQL 中的表现 LIKE 之注意事项 运用通配符的技巧 Understanding Order of Evalu ...
- MySQL Crash Course #01# Chapter 1. 2 概念. Primary key
索引 database table schema Primary Key MySQL 书的第一章介绍一些基本的概念.理解数据库是掌握 MySQL 非常重要的一个部分. 第二章简单介绍了 MySQL 以 ...
- MySQL Crash Course #21# Chapter 29.30. Database Maintenance & Improving Performance
终于结束这本书了,最后两章的内容在官方文档中都有详细介绍,简单过一遍.. 首先是数据备份,最简单直接的就是用 mysql 的内置工具 mysqldump MySQL 8.0 Reference Man ...
- MySQL Crash Course #17# Chapter 25. 触发器(Trigger)
推荐看这篇mysql 利用触发器(Trigger)让代码更简单 以及 23.3.1 Trigger Syntax and Examples 感觉有点像 Spring 里的 AOP 我们为什么需要触发器 ...
随机推荐
- C++/C, Java学习资料
C++11系列-什么是C++11 [Java]Final 与 C++ Const的区别 C++开发者都应该使用的10个C++11特性 史上最明白的 NULL.0.nullptr 区别分析 C语言堆栈入 ...
- 2018-2019-2 20165330《网络对抗技术》Exp2 后门原理与实践
目录 基础问题 相关知识 实验内容 实验步骤 实验过程中遇到的问题 实验总结与体会 实验内容 使用netcat获取主机操作Shell,cron启动 使用socat获取主机操作Shell, 任务计划启动 ...
- DS作业·写了一个链表
用struct手写了个list 有push_back,push_front,insert,erase reserve,size,setpos,rbegin 功能. 坑:一开始想用template< ...
- android speakerphone/
http://www.cnblogs.com/innost/archive/2011/01/22/1942149.html http://blog.sina.com.cn/s/blog_5418969 ...
- django模板语言的注释
就像HTML或者Python,Django模板语言同样提供代码注释. 注释使用 {# #} : ? 1 {# This is a comment #} 注释的内容不会在模板渲染时输出. 用这种语法的注 ...
- Python开发【数据结构】:字典内部剖析
字典内部剖析 开篇先提出几个疑问: 所有的类型都可以做字典的键值吗? 字典的存储结构是如何实现的? 散列冲突时如何解决? 最近看了一些关于字典的文章,决定通过自己的理解把他们写下来:本章将详细阐述上面 ...
- mysql 权限管理 针对库 授权 db.*
需求 只放行user表 db1库的select权限 mysql> grant select on db1.* to 'mike'@'localhost'; Query OK, rows affe ...
- mysql 内置功能 存储过程 目录
mysql 内置功能 存储过程介绍 mysql 内置功能 存储过程 创建无参存储过程 mysql 内置功能 存储过程 创建有参存储过程 mysql 内置功能 存储过程 删除存储过程
- UIAlertview 添加图片
- (void)willPresentAlertView:(UIAlertView *)alertView { 在这个方法中, 绘制需要的东西 uiview *myView = [uiview all ...
- C#静态类,静态构造函数,静态变量
静态变量位于栈上,它是一个全局变量,在编译期就已经生成. public class Cow public static int count; private int id; { id = ++coun ...