MySQL安全性指南(2)
作 者: 晏子
2.1.3 数据库和表权限
下列权限运用于数据库和表上的操作。
ALTER
允许你使用ALTER TABLE语句,这其实是一个简单的第一级权限,你必须由其他权限,这看你想对数据库实施什么操作。
CREATE
允许你创建数据库和表,但不允许创建索引。
DELETE
允许你从表中删除现有记录。
DROP
允许你删除(抛弃)数据库和表,但不允许删除索引。
INDEX
允许你创建并删除索引。
REFERENCES
目前不用。
SELECT
允许你使用SELECT语句从表中检索数据。对不涉及表的SELECT语句就不必要,如SELECT NOW()或SELECT 4/2。
UPDATE
允许你修改表中的已有的记录。
2.1.4 管理权限
下列权限运用于控制服务器或用户授权能力的操作的管理性操作。
FILE
允许你告诉服务器读或写服务器主机上的文件。该权限不应该随便授予,它很危险,见“回避授权表风险”。服务器确实较谨慎地保持在一定范围内使用该权限。你只能读任何人都能读的文件。你正在写的文件必须不是现存的文件,这防止你迫使服务器重写重要文件,如/etc/passwd或属于别人的数据库的数据目录。
如果你授权FILE权限,确保你不以UNIX的root用户运行服务器,因为root可在文件系统的任何地方创建新文件。如果你以一个非特权用户运行服务器,服务器只能在给用户能访问的目录中创建文件。
GRANT
允许你将你自己的权限授予别人,包括GRANT。
PROCESS
允许你通过使用SHOW PROCESS语句或mysqladmin process命令查看服务器内正在运行的线程(进程)的信息。这个权限也允许你用KILL语句或mysqladmin kill命令杀死线程。
你总是能看到或杀死你自己的线程。PROCESS权限赋予你对任何线程做这些事情的能力。
RELOAD
允许你执行大量的服务器管理操作。你可以发出FLUSH语句,你也能指性mysqladmin的reload、refresh、flush-hosts、flush-logs、flush-privileges和flush-tables等命令。
SHUTDOWN
允许你用mysqladmin shutdown关闭服务器。
在user、db和host表中,每一个权限以一个单独的列指定。这些列全部声明为一个ENUM("N","Y")类型,所以每个权的缺省值是“N”。在tables_priv和columns_priv中的权限以一个SET表示,它允许权限用一个单个列以任何组合指定。这两个表比其他三个表更新,这就是为什么它们使用更有效的表示方式的原因。(有可能在未来,user、db和host表也用一个SET类型表示。)
在tables_priv表中的Table_priv列被定义成:
SET('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter')
在coloums_priv表中的Column_priv列被定义成:
SET('Select','Insert','Update','References')
列权限比表权限少,因为列级较少的权限有意义。例如你能创建一个表,但你不能创建一个孤立的列。
user表包含某些在其他授权表不存在的权限的列:File_priv、Process_priv、Reload_priv和Shutdown_priv。这些权限运用于你让服务器执行的与任何特定数据库或表不相关的操作。如允许一个用户根据当前数据库是什么来关闭数据库是毫无意义的。

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


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

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

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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),
