限制用户的操作权限并不是怕有人恶意搞破坏,而是为了减少失误操作的可能性。

详细文档: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的更多相关文章

  1. MySQL Crash Course #18# Chapter 26. Managing Transaction Processing

    InnoDB 支持 transaction ,MyISAM 不支持. 索引: Changing the Default Commit Behavior SAVEPOINT 与 ROLLBACK TO ...

  2. 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 ...

  3. MySQL Crash Course #13# Chapter 21. Creating and Manipulating Tables

    之前 manipulate 表里的数据,现在则是 manipulate 表本身. INDEX 创建多列构成的主键 自动增长的规定 查看上一次插入的自增 id 尽量用默认值替代 NULL 外键不可以跨引 ...

  4. MySQL Crash Course #10# Chapter 19. Inserting Data

    INDEX BAD EXAMPLE Improving Overall Performance Inserting Multiple Rows INSTEAD OF Inserting a Singl ...

  5. MySQL Crash Course #06# Chapter 13. 14 GROUP BY. 子查询

    索引 理解 GROUP BY 过滤数据 vs. 过滤分组 GROUP BY 与 ORDER BY 之不成文的规定 子查询 vs. 联表查询 相关子查询和不相关子查询. 增量构造复杂查询 Always ...

  6. 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 ...

  7. MySQL Crash Course #01# Chapter 1. 2 概念. Primary key

    索引 database table schema Primary Key MySQL 书的第一章介绍一些基本的概念.理解数据库是掌握 MySQL 非常重要的一个部分. 第二章简单介绍了 MySQL 以 ...

  8. MySQL Crash Course #21# Chapter 29.30. Database Maintenance & Improving Performance

    终于结束这本书了,最后两章的内容在官方文档中都有详细介绍,简单过一遍.. 首先是数据备份,最简单直接的就是用 mysql 的内置工具 mysqldump MySQL 8.0 Reference Man ...

  9. MySQL Crash Course #17# Chapter 25. 触发器(Trigger)

    推荐看这篇mysql 利用触发器(Trigger)让代码更简单 以及 23.3.1 Trigger Syntax and Examples 感觉有点像 Spring 里的 AOP 我们为什么需要触发器 ...

随机推荐

  1. CSU 1803 - 2016 - [同余]

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. ...

  2. Pandas的loc方法

    当你读取到DataFrame的数据时,想去定位某一个数据项,可以使用loc方法进行查找,之后你可以赋值给他. import pandas as pd df = pd.read_csv('file_na ...

  3. WebFlux Spring Security配置

    最小化可运行配置 package com.terwergreen.bugucms.config; import org.apache.commons.logging.Log; import org.a ...

  4. MYSQL数据库建表注意事项

    1.库名.表名.字段名必须使用小写字母,“_”分割. 原因: MySQL在Linux下数据库名.表名.列名.别名大小写规则是这样的: 1.数据库名与表名是严格区分大小写的: 2.表的别名是严格区分大小 ...

  5. 控制div显示隐藏(有文字图片介绍)

    <div class="toggle"> <p id="zi">收起</p> <p id="zhe" ...

  6. 前端 html input标签 placeholder属性 标签上显示内容

    前端 html  input标签 的placeholder属性  标签上显示内容 <!DOCTYPE html> <html lang="en"> < ...

  7. Python3学习之路~2.1 列表、元组操作

    列表 列表是我们以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作. 定义列表(list) names=['Amy','Bob','Cindy','David'] 通过下标访问列 ...

  8. 010-spring cloud gateway-过滤器-自定义局部、全局过滤器、区别

    一.自定义局部过滤器 自定义过滤器需要实现GatewayFilter和Ordered.其中GatewayFilter中的这个方法就是用来实现你的自定义的逻辑的 Mono<Void> fil ...

  9. mathType插入公式编号,及对公式编号的字体进行修改。调整公式上下间距。

    一:插入 公式编号. 1:首先设置公式格式.点击 mathtype>insert number >format 2:有简单格式和 高级格式:              https://we ...

  10. [py]字符串/列表

    去除str首尾空格(切片) ## str长度 循环,判断 ### [:i] [i:] 记录位置点 ## 方法1 def trim2(s): s2 = "" start = 0 en ...