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 我们为什么需要触发器 ...
随机推荐
- (转载)准确率(accuracy),精确率(Precision),召回率(Recall)和综合评价指标(F1-Measure )-绝对让你完全搞懂这些概念
自然语言处理(ML),机器学习(NLP),信息检索(IR)等领域,评估(evaluation)是一个必要的工作,而其评价指标往往有如下几点:准确率(accuracy),精确率(Precision),召 ...
- JavaScript之Function 和 Object 的区别和联系
1.先看一个控制台的输出: instanceof 运算符字面意思是 左边是右边的一个实例吗? 但是这两条输出让人很困惑.Function 是 Object 的实例.Object 也是 Function ...
- phpstrom 配置xdebug在vagrant上调试
参数 linux system : centos6. vagrant: PHP: phpstrom:2017.2 步骤1: 安装xdebug扩展(已安装可跳过步骤1),首先去 xdebug官方下载扩展 ...
- AWTK 全称为 Toolkit AnyWhere,是 ZLG 倾心打造的一套基于 C 语言开发的 GUI 框架(三平台+2个手机平台+嵌入式)
最终目标: 支持开发嵌入式软件. 支持开发Linux应用程序. 支持开发MacOS应用程序. 支持开发Windows应用程序. 支持开发Android应用程序. 支持开发iOS应用程序. 支持开发2D ...
- 深入了解oracle存储过程的优缺点
定义: 存储过程(Stored Procedure )是一组为了完成特定功能的SQL 语句集,经编译后存储在数据库中.用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它.存储过程是 ...
- Shell初学(一)hello world
精简: 1.创建:可以使用 vi/vim 命令来创建文件如: test.sh ,扩展名并不影响脚本执行,写什么都可以. 2.hello_world: #!/bin/bash ...
- appstore加速审核通道
申请入口:https://developer.apple.com/contact/app-store/?topic=expedite
- Inception系列
从GoogLeNet的Inceptionv1开始,发展了众多inception,如inception v2.v3.v4与Inception-ResNet-V2. 故事还是要从inception v1开 ...
- HDU Today(自己的代码不知道哪里错了一直没A抄袭大神的)
http://acm.hdu.edu.cn/showproblem.php?pid=2112 本题题目意思非常简单,麻烦的就是处理一下字符串,这是我能力欠缺的地方 ;} 先把我有乱有麻烦的错误代码贴上 ...
- Summary: Class Variable vs. Instance Variable && Class Method
这里列举的是一些我平时碰到的一些Java Grammar,日积月累. Class Variable vs Instance Variable: Instance variables Instance ...