MySQL技术内幕-InnoDB存储引擎-读书笔记(二)
作为php开发,使用mysql总是少不了的
系列文章博客链接 http://itsong.net/articles/466.html
第三章 文件
mysql与innodb几个类型的文件
参数文件,配置路径、初始化参数、内存大小等 日志文件,包括错误日志,二进制日志,慢查询日志,查询日志 socket文件,用unix域套接字,unix domain socket来进行连接时需要的文件,这一般是本机连接,比通常tcp快 pid文件,进程id文件 表结构文件,存放表结构定义的文件 存储引擎文件,每个存储引擎自己搞文件保存数据,包括数据和索引等。*
参数文件
musql --help | grep my.cnf可以寻找加载哪些参数文件 静态参数,整个实例生命周期不得更改,类似只读。 动态参数,可以通过set命令进行更改<code class="hljs sql">SET | [global | session] system_var_name = expr | [@@global. | @@session. | @@]system_var_name = expr</code>
global与session表示该参数的修改基于当前会话还是整个实例的生命周期。
日志文件
错误日志,show variables like 'log_error'定位错误日志,默认情况下,文件名为服务器主机名.err 慢查询日志,阈值通过 long_query_time 修改,默认值10秒(含义是大于10,不包括10),默认不启动慢查询日志,要将 log_slow_queries 设为ON,mysqldumpslow可以解决日志过多难以解决的问题 从5.1开始,慢查询可以以微秒记录。并且慢查询会进表,叫mysql.slow_log,通过log_output(FILE | TABLE)指定 log_queries_not_using_indexes,记录没有使用索引的慢查询日志文件 查询日志,默认文件名为主机名.log,也可以进表,general_log 二进制日志,记录对数据库执行更改的所有操作,不包括SELECT和SHOW这类操作。包括操作时间和执行时间等信息。主要用来恢复、复制(master,slave实时同步) 二进制日志所在目录show variables like 'datadir',默认文件名为主机名,后缀为序列号,bin_log.index为二进制的索引文件,存储日志序号 默认二进制日志未开启,开启binlog性能下降1%,但是可以接受的 查看binlog要使用mysqlbinlog,binlog还有很多操作,不过这里我不太关心啦
其他
套接字文件,一般再/tmp下,mysql.sock pid文件,主机名.pid,variables 为 pid_file 表结构定义文件,frm后缀名的文件,记录的表结构定义以及视图定义,文本文件,可以直接cat
innodb存储引擎文件
存储的数据按表空间进行存放,默认会有一个初始化大小为10MB,名为ibdata1的文件,默认表空间。 设置innodb_data_file_path参数后,innodb存储引擎的表的数据都会记录到该文件内。 设置innodb_file_per_table,每个基于innodb存储引擎的表单独产生一个表空间,文件名为表名.ibd,就不会进入默认表空间。 这些单独的表空间文件仅存储该表的数据,索引和插入缓冲等信息,其余信息还是存放在默认的表空间。
重做日志文件
ib_logfile0和ib_logfile1,记录了innodb存储引擎的事务日志 每个文件写到文件最后时,切换至另一个日志文件去写,为了得到更高的可靠性,可以设置多个镜像日志组

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