经验谈之MySQL安全问题的一点心得_MySQL
前两天在帮朋友整理他的主页空间时候,发现的一点关于MySQL可能大家都会忽略的问题:我们知道,在安装完MySQL后,它会自动创建一个root用户和一个匿名用户,其初始密码都是空,对于前者,很多参考资料上都会提醒大家要注意及时设定一个密码,而忽略了后者,大概是因为后者默认设定为只能在本机使用的缘故吧。 Eu,idWG
.1T9C=
但如果你的MySQL是要提供给Web服务器作数据库服务的,忽略这个匿名用户的代价可能相当惨重,因为在默认设置下,这个匿名用户在localhost上几乎拥有和root一样的权限,这时候,如果你的客户拥有上传脚本文件、脚本文件可以进行MySQL数据库操作(比如允许操作MySQL的php)的权限已经可能将你的MySQL改动得面目全非了: H xqSnXIrf
]sljuwG_
我今天帮朋友整理他的主页空间的时候,试着写了一个很简单的执行sql语句的php文件上传上去,其中连接字中的user,password我都试着置空,host=localhost,结果发现我的sql语句可以执行,于是执行select * from MySQL.user察看用户权限,发现这个用户在localhost权限非常高,连grant_priv都有,(察看的时候,会发现在root用户下有两行用户名、密码为空的,但各项权限有y 的,就是这个匿名用户本地、远程权限设置了) N ]]ms
2f_-&hhU
所以我试着用这个php页面创建一个新用户,并grant给他较高的权限,结果一举成功,这样我就可以用这个新用户通过我本机的MySQL client连接到这个网站的MySQL server,并用这个新建立的用户的管理权限对这个网站的MySQL server进行管理,看到自己可以进行这样轻易获得深入的数据库操作,我怎么还敢把朋友的主页空间的敏感资料放入这个MySQL server呢? S> PLm}0
{Ri
改进建议: GNe=Ar8
],? WS{
1、在安装完成MySQL 后,不仅改变root用户的的密码,也同时改变匿名用户的密码,方法类似改变root的密码的方式: _ I!xM_Yr
3Os+j+r@
MySQL> UPDATE user set password=PASSWORD(´yournewpassword´) where user=´´; i dX"$T+f
MySQL>FLUSH PRIVILEGES; [&4NS-F;P
"5N 5 5|-}
2、如非必要,删除这个匿名用户,这样所有人要使用MySQL 都必须提供用户名,即便日后出了问题,也容易查找问题的源头。 ji??)QZs
t 6C6hk
3、除了root用户外,其他用户包括匿名用户(如果没有删除这个用户)不应该拥有grant权限,防止管理权限不受控制的扩散出去。 C0fXOO"y"t
#B T I6W
4、赋予用户updatedeletealertcreatedrop权限的时候,应该限定到特定的数据库,尤其要避免普通客户拥有对MySQL数据库做操作的权限,否则你的系统设置很可能被替换掉。 HxTC$:/
Fzru24^
5、检查MySQL.user表,取消不必要用户的shutdown_priv,reload_priv,process_priv和File_priv权限,这些权限可能泄漏更多的服务器信息包括非MySQL的其它信息出去。 t-_[3#;
+__8*bLLR
6、如果不打算让你的用户使用MySQL数据库,在提供诸如php这样的脚本语言的时候,重新设置或编译你的php,取消它们对MySQL的默认支持。

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi


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

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
