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>
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] ...例子:
假如你要删除用户jeffrey@localhost 对所有数据库的插入权限,请用下边命令
REVOKE INSERT ON *.* FROM 'jeffrey'@'localhost';
假如你还要随便删除其授权的权限,可用:
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>]
当 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>查看root用户权限:
<span>SHOW GRANTS FOR 'ROOT'@'LOCALHOST'</span>
四、实际应用及一些坑

The steps to create and manage user accounts in MySQL are as follows: 1. Create a user: Use CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password'; 2. Assign permissions: Use GRANTSELECT, INSERT, UPDATEONmydatabase.TO'newuser'@'localhost'; 3. Fix permission error: Use REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost'; then reassign permissions; 4. Optimization permissions: Use SHOWGRA

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

The disadvantages of MySQL compared to other relational databases include: 1. Performance issues: You may encounter bottlenecks when processing large-scale data, and PostgreSQL performs better in complex queries and big data processing. 2. Scalability: The horizontal scaling ability is not as good as Google Spanner and Amazon Aurora. 3. Functional limitations: Not as good as PostgreSQL and Oracle in advanced functions, some functions require more custom code and maintenance.

MySQL supports four JOIN types: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN is used to match rows in two tables and return results that meet the criteria. 2.LEFTJOIN returns all rows in the left table, even if the right table does not match. 3. RIGHTJOIN is opposite to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet the conditions.

MySQL's performance under high load has its advantages and disadvantages compared with other RDBMSs. 1) MySQL performs well under high loads through the InnoDB engine and optimization strategies such as indexing, query cache and partition tables. 2) PostgreSQL provides efficient concurrent read and write through the MVCC mechanism, while Oracle and Microsoft SQLServer improve performance through their respective optimization strategies. With reasonable configuration and optimization, MySQL can perform well in high load environments.

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

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.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.


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

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.