MySQL 权限管理相关
MySQL 权限管理相关 本文通过理论联系实际操作,对MySQL权限相关的知识点做出梳理,并在实际应用中慢慢补充完善。 一、MySQL用户有哪些权限 以下部分copy自网上,点击浏览该博文 MYSQL到底都有哪些权限呢?从官网复制一个表来看看: 权限 权限级别 权限说明
MySQL 权限管理相关
本文通过理论联系实际操作,对MySQL权限相关的知识点做出梳理,并在实际应用中慢慢补充完善。
一、MySQL用户有哪些权限
以下部分copy自网上,点击浏览该博文
MYSQL到底都有哪些权限呢?从官网复制一个表来看看:
权限
权限级别
权限说明
CREATE
数据库、表或索引
创建数据库、表或索引权限
DROP
数据库或表
删除数据库或表权限
GRANT OPTION
数据库、表或保存的程序
赋予权限选项
REFERENCES
数据库或表
ALTER
表
更改表,比如添加字段、索引等
DELETE
表
删除数据权限
INDEX
表
索引权限
INSERT
表
插入权限
SELECT
表
查询权限
UPDATE
表
更新权限
CREATE VIEW
视图
创建视图权限
SHOW VIEW
视图
查看视图权限
ALTER ROUTINE
存储过程
更改存储过程权限
CREATE ROUTINE
存储过程
创建存储过程权限
EXECUTE
存储过程
执行存储过程权限
FILE
服务器主机上的文件访问
文件访问权限
CREATE TEMPORARY TABLES
服务器管理
创建临时表权限
LOCK TABLES
服务器管理
锁表权限
CREATE USER
服务器管理
创建用户权限
PROCESS
服务器管理
查看进程权限
RELOAD
服务器管理
执行flush-hosts, flush-logs, flush-privileges, flush-status, flush-tables, flush-threads, refresh, reload等命令的权限
REPLICATION CLIENT
服务器管理
复制权限
REPLICATION SLAVE
服务器管理
复制权限
SHOW DATABASES
服务器管理
查看数据库权限
SHUTDOWN
服务器管理
关闭数据库权限
SUPER
服务器管理
执行kill线程权限
MySQL的权限如何分布,就是针对表可以设置什么权限,针对列可以设置什么权限等等,这个可以从官方文档中的一个表来说明:
权限分布
可能的设置的权限
表权限
'Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Grant', 'References', 'Index', 'Alter'
列权限
'Select', 'Insert', 'Update', 'References'
过程权限
'Execute', 'Alter Routine', 'Grant'
二、MySQL权限经验原则:
权限控制主要是出于安全因素,因此需要遵循一下几个经验原则:
1、只授予能满足需要的最小权限,防止用户干坏事。比如用户只是需要查询,那就只给select权限就可以了,不要给用户赋予update、insert或者delete权限。
2、创建用户的时候限制用户的登录主机,一般是限制成指定IP或者内网IP段。
3、初始化数据库的时候删除没有密码的用户。安装完数据库的时候会自动创建一些用户,这些用户默认没有密码。
4、为每个用户设置满足密码复杂度的密码。
5、定期清理不需要的用户。回收权限或者删除用户。
三、权限增、删、查、改操作
添加:
权限的添加用grant (文档)命令来添加,具体格式如下:
GRANT <span><code>priv_type</code></span> [(<span><code>column_list</code></span>)] [, <span><code>priv_type</code></span> [(<span><code>column_list</code></span>)]] ... ON [<span><code>object_type</code></span>] <span><code>priv_level</code></span> TO <span><code>user_specification</code></span> [, <span><code>user_specification</code></span>] ... [REQUIRE {NONE | <span><code>ssl_option</code></span> [[AND] <span><code>ssl_option</code></span>] ...}] [WITH <span><code>with_option</code></span> ...] <span><code>object_type</code></span>: TABLE | FUNCTION | PROCEDURE <span><code>priv_level</code></span>: * | *.* | <span><code>db_name</code></span>.* | <span><code>db_name.tbl_name</code></span> | <span><code>tbl_name</code></span> | <span><code>db_name</code></span>.<span><code>routine_name</code> <code>user_specification</code></span>: <span><code>user</code></span> [IDENTIFIED BY [PASSWORD] '<span><code>password</code></span>'] <span><code>ssl_option</code></span>: SSL | X509 | CIPHER '<span><code>cipher</code></span>' | ISSUER '<span><code>issuer</code></span>' | SUBJECT '<span><code>subject</code></span>' <span><code>with_option</code></span>: GRANT OPTION | MAX_QUERIES_PER_HOUR <span><code>count</code></span> | MAX_UPDATES_PER_HOUR <span><code>count</code></span> | MAX_CONNECTIONS_PER_HOUR <span><code>count</code></span> | MAX_USER_CONNECTIONS <span><code>count</code></span>Copy after login
PS:
with_option 是对所授权限的一些限制或管理,例如 with grant option 表示被授权的用户拥有对其他用户授予同样权限的能力
删除:
权限的删除用revoke (官方文档)命令来添加,具体格式如下:
REVOKE priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [object_type] priv_level FROM user [, user] ... REVOKE ALL PRIVILEGES, GRANT OPTION FROM user [, user] ...Copy after login例子:
假如你要删除用户jeffrey@localhost 对所有数据库的插入权限,请用下边命令
REVOKE INSERT ON *.* FROM 'jeffrey'@'localhost';Copy after login
假如你还要随便删除其授权的权限,可用:
REVOKE grant option ON *.* FROM 'jeffrey'@'localhost';
当然,你也可以向赋予权限那样用all privilege删除所有权限(ps:all privilege 不包含 grant 权限)
REVOKE all privileges ON *.* FROM 'jeffrey'@'localhost';
查看:
show grants (官方文档)命令由于查看用户的权限
SHOW GRANTS [FOR <span><code>user</code></span>]Copy after login
当 for user被缺省时,显示所有查询用户可见用户的权限:
<span style="font-size:14px;">mysql> show grants; +------------------------------------------------------------------------------- ---------------------------------------------------------+ | Grants for root@localhost | +------------------------------------------------------------------------------- ---------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F 5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +------------------------------------------------------------------------------- ---------------------------------------------------------+ 2 rows in set (0.00 sec)</span>
<span>SHOW GRANTS FOR 'ROOT'@'LOCALHOST'</span>Copy after login
四、实际应用及一些坑

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.
