概述
文章简单介绍了通过一些查询命令分析当前服务器的状态。
目录
概述
获取服务器整体的性能状态
SQL操作计数
总结
步骤
获取服务器整体的性能状态
首先对一个数据库服务器进行性能优化需要先知道服务器当前主要的性能问题出现在哪里,在这点sql server也是类似,sql server首先会分析当前服务器的等待类型的情况。
我们可以使用show [session|global] status命令来获取想要的信息,默认是显示当前连接的所有统计参数值,还可以直接查询information_schema数据库中的session_status表。
show status;
#或者使用
use information_schema;
select * from SESSION_STATUS;
我当前的mysql版本是5.6.21,总共查询出了341行参数。
这里有一篇文章详细分析了每一个参数值的所代表的意思:http://blog.sina.com.cn/s/blog_68baf43d0100vu2x.html
SQL操作计数
接下来我们主要分析里面的com_参数,com_参数各种SQL对数据库执行的操作。
show status like 'com_%';
#或者使用
use information_schema;
select * from SESSION_STATUS WHERE variable_name like 'com_%';
各种SQL操作计数总共有142个,不同的版本结果不一样,接下来就来测试一下,表中的alter table的当前连接的操作次数为0,现在我修改一下表看看结果。
ALTER TABLE test ADD Name CHAR(10) NOT NULL;
show status like 'com_%';
可以看到alter_table计数增加了1。
com_计数里面有几个比较重要的参数,其它的一些参数也经常用来做参考。
com_delete:执行delete操作的次数。
com_select:执行select操作的次数。
com_insert:执行insert操作的次数,对应批量插入操作无论里面循环多少次都只算一次。
com_update:执行update操作的次数。
com_commit:执行事务提交的次数。
com_rollback:执行事务回滚的次数。
上面的计数包括所有的存储引擎,有几个参数是单独针对innodb存储引擎,记录了read,inserted,updated,deleted每种操作的行数。
show status like 'innodb_rows%';
#或者使用
use information_schema;
select * from SESSION_STATUS WHERE variable_name like 'innodb_rows%';
定位效率低的SQL语句
1.可以通过慢查询日志来定位,慢查询只能查询已经执行结束的语句,如果要查询当前正发生的问题无法做到,这个方法在后面一篇文章介绍mysql日志会详细介绍。
由于我将慢查询的时间设为0.01秒,所以超过这个值的都会记录下来,上面的截图就是慢查询日志里面的一条SQL操作记录,记录中记录了在什么时候执行的操作,执行操作的用户信息,执行花了0.19秒,锁花了0.001秒,返回了0行,查询了1行。
2.使用show processlist命令查询当前进行线程,该命令经常用来分析当前服务器的状况。
上图中有后四个字段需要理解,其中
command:记录了当前查询的一个状态,休眠(sleep),查询(query),连接(connect)。
Time:持续的时间,单位是秒,经常会使用这个值来做分析操作。
state:当前语句的状态,这个状态值很重要,这个状态值很多,大家可以去了解一下,上图就是等待表解锁。
info:记录操作语句
3.借助第三方监控工具
总结
文章的知识点涉及的内容其实很多,这里只是简单的写了一下,包括服务器里的很多状态都是很重要的,文章只是单单拿出了SQL操作的计数来讲,其它的一些包括connections,slow_queries,innodb_data_,innodb_buffer_pool_等等都是非常有用的一些计数,由于太多这里就没有全部拿出来分析,文章中也给出了一个连接介绍了其它的一些计数的含义。

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
