关于java:Mysql优化操作学习纪录

6次阅读

共计 6184 个字符,预计需要花费 16 分钟才能阅读完成。

SHOW STATUS;
FLUSH STATUS;

查看以后连接数 SHOW STATUS LIKE ‘Thread_%’;
Thread_cached: 被缓存的线程的个数
Thread_running:处于激活状态的线程的个数
Thread_connected:以后连贯的线程的个数
Thread_created:总共被创立的线程的个数

Thread cache hits
Thread_connected = SHOW GLOBAL STATUS LIKE Thread_created;
Connections = SHOW GLOBAL STATUS LIKE ‘Connections’;
TCH=(1 – (Threads_created / Connections)) * 100

查看流动连贯内容
SHOW PROCESSLIST;

如果 TCH 数小于 90%, 创立连贯消耗了工夫, 增大 Thread_cached 数量

QPS(每秒查询处理量)MyISAM 引擎

Questions = SHOW GLOBAL STATUS LIKE ‘Questions’;
Uptime = SHOW GLOBAL STATUS LIKE ‘Uptime’;
QPS=Questions/Uptime

TPS(每秒传输的事物解决个数),即服务器每秒解决的事务数,如果是 InnoDB 会显示,没有 InnoDB 就不会显示。

Com_commit = SHOW GLOBAL STATUS LIKE ‘Com_commit’;
Com_rollback = SHOW GLOBAL STATUS LIKE ‘Com_rollback’;
Uptime = SHOW GLOBAL STATUS LIKE ‘Uptime’;
TPS=(Com_commit + Com_rollback)/Uptime

QPS 和 TPS 值肯定要实时监控, 如果靠近架构搭建时的测试峰值, 愿上帝与你同在

Read/Writes Ratio
Qcache_hits = SHOW GLOBAL STATUS LIKE ‘Qcache_hits’;
Com_select = SHOW GLOBAL STATUS LIKE ‘Com_select’;
Com_insert = SHOW GLOBAL STATUS LIKE ‘Com_insert’;
Com_update = SHOW GLOBAL STATUS LIKE ‘Com_update’;
Com_delete = SHOW GLOBAL STATUS LIKE ‘Com_delete’;
Com_replace = SHOW GLOBAL STATUS LIKE ‘Com_replace’;
R/W=(Com_select + Qcache_hits) / (Com_insert + Com_update + Com_delete + Com_replace) * 100

读写比, 优化数据库的重要依据, 读的多就去优化读, 写的多就去优化写

Slow queries per minute
Slow_queries = SHOW GLOBAL STATUS LIKE ‘Slow_queries’;
Uptime = SHOW GLOBAL STATUS LIKE ‘Uptime’;
SQPM=Slow_queries / (Uptime/60)

Slow queries /Questions Ratio
Slow_queries = SHOW GLOBAL STATUS LIKE ‘Slow_queries’;
Questions = SHOW GLOBAL STATUS LIKE ‘Questions’;
S/Q=Slow_queries/Questions

新版本上线时要着重关注慢查问, 让测试去踢开发者的屁股吧

Full_join per minute
Select_full_join = SHOW GLOBAL STATUS LIKE ‘Select_full_join’;
Uptime = SHOW GLOBAL STATUS LIKE ‘Uptime’;
FJPM=Select_full_join / (Uptime/60)

没有应用索引而造成的 full_join, 优化索引去吧

Innodb buffer read hits
Innodb_buffer_pool_reads = SHOW GLOBAL STATUS LIKE ‘Innodb_buffer_pool_reads’;
Innodb_buffer_pool_read_requests = SHOW GLOBAL STATUS LIKE ‘Innodb_buffer_pool_read_requests’;
IFRH=(1 – Innodb_buffer_pool_reads/Innodb_buffer_pool_read_requests) * 100

InnoDB Buffer 命中率 指标 95%-99%;

Table Cache
Open_tables= SHOW GLOBAL STATUS LIKE ‘Open_tables’;
Opened_tables= SHOW GLOBAL STATUS LIKE ‘Opened_tables’;
table_cache= SHOW GLOBAL STATUS LIKE ‘table_cache’;

table_cache 应该大于 Open_tables 小于 Opened_tables

Temp tables to Disk ratio

Created_tmp_tables = show global status like ‘Created_tmp_tables’;
Created_tmp_disk_tables = show global status like ‘Created_tmp_disk_tables’;

TDR=(Created_tmp_disk_tables/Created_tmp_tables)*100

SHOW GLOBAL STATUS LIKE ‘Innodb_row_lock_%’;

  • Innodb_row_lock_current_waits

    The number of row locks currently being waited for. Added in MySQL 5.0.3.

  • Innodb_row_lock_time

    The total time spent in acquiring row locks, in milliseconds. Added in MySQL 5.0.3.

  • Innodb_row_lock_time_avg

    The average time to acquire a row lock, in milliseconds. Added in MySQL 5.0.3.

  • Innodb_row_lock_time_max

    The maximum time to acquire a row lock, in milliseconds. Added in MySQL 5.0.3.

  • Innodb_row_lock_waits

    The number of times a row lock had to be waited for. Added in MySQL 5.0.3.

——————————————————————————————————————————————————

1. 零碎 mysql 的过程数

ps -ef | grep “mysql” | grep -v “grep” | wc –l

2.Slave_running

mysql > show status like ‘Slave_running’;

如果零碎有一个从复制服务器,这个值指明了从服务器的衰弱度

3.Threads_connected

mysql > show status like ‘Threads_connected’;

以后客户端已连贯的数量。这个值会少于预设的值,但你也能监督到这个值较大,这可保障客户端是处在沉闷状态。

4.Threads_running

mysql > show status like ‘Threads_running’;

如果数据库超负荷了,你将会失去一个正在(查问的语句继续)增长的数值。这个值也能够少于事后设定的值。这个值在很短的工夫内超过限定值是没问题的。当 Threads_running 值超过预设值时并且该值在 5 秒内没有回落时,要同时监督其余的一些值。

5.Aborted_clients

mysql > show status like ‘Aborted_clients’;

客户端被异常中断的数值,即连贯到 mysql 服务器的客户端没有失常地断开或敞开。对于一些应用程序是没有影响的,但对于另一些应用程序可能你要跟踪该值,因为异常中断连贯可能表明了一些应用程序有问题。

6.Questions

mysql> show status like ‘Questions’;

每秒钟取得的查问数量,也能够是全副查问的数量,依据你输出不同的命令会失去你想要的不同的值。

7.Handler_*

mysql> show status like ‘Handler_%’;

如果你想监督底层(low-level)数据库负载,这些值是值得去跟踪的。

如果 Handler_read_rnd_next 值绝对于你认为是正常值相差悬殊,可能会通知你须要优化或索引出问题了。Handler_rollback 表明事务被回滚的查问数量。你可能想考察一下起因。

8.Opened_tables

mysql> show status like ‘Opened_tables’;

表缓存没有命中的数量。如果该值很大,你可能须要减少 table_cache 的数值。典型地,你可能想要这个值每秒关上的表数量少于 1 或 2。

9.Select_full_join

mysql> show status like ‘Select_full_join’;

没有主键(key)联结(Join)的执行。该值可能是零。这是捕捉开发谬误的好办法,因为一些这样的查问可能升高零碎的性能。

10.Select_scan

mysql> show status like ‘Select_scan’;

执行全表搜寻查问的数量。在某些状况下是没问题的,但占总查问数量该比值应该是常量(即 Select_scan/ 总查问数量商应该是常数)。如果你发现该值持续增长,阐明须要优化,不足必要的索引或其余问题。

11.Slow_queries

mysql> show status like ‘Slow_queries’;

超过该值(–long-query-time)的查问数量,或没有应用索引查问数量。对于全副查问会有小的抵触。如果该值增长,表明零碎有性能问题。

12.Threads_created

mysql> show status like ‘Threads_created’;

该值应该是低的。较高的值可能意味着你须要减少 thread_cache 的数值,或你遇到了继续减少的连贯,表明了潜在的问题。

13. 客户端连贯过程数

shell> mysqladmin processlist

mysql> show processlist;

你能够通过应用其余的统计信息失去已连接线程数量和正在运行线程的数量,查看正在运行的查问花了多长时间是一个好主见。如果有一些长时间的查问,管理员能够被告诉。你可能也想理解多少个查问是在 ”Locked” 的状态—— 该值作为正在运行的查问不被计算在内而是作为非沉闷的。一个用户正在期待一个数据库响应。

14.innodb 状态

mysql> show innodb status;

该语句产生很多信息,从中你能够失去你感兴趣的。首先你要查看的就是“从最近的 XX 秒计算出来的每秒的均匀负载”。

(1)Pending normal aio reads: 该值是 innodb io 申请查问的大小(size)。如果该值大到超过了 10—20,你可能有一些瓶颈。

(2)reads/s, avg bytes/read, writes/s, fsyncs/s: 这些值是 io 统计。对于 reads/writes 大值意味着 io 子系统正在被装载。适当的值取决于你零碎的配置。

(3)Buffer pool hit rate: 这个命中率十分依赖于你的应用程序。当你感觉有问题时请查看你的命中率

(4)inserts/s, updates/s, deletes/s, reads/s: 有一些 Innodb 的底层操作。你能够用这些值查看你的负载状况查看是否是期待的数值范畴。

15. 主机性能状态

shell> uptime

16.CPU 使用率

shell> top

shell> vmstat

17. 磁盘 IO

shell> vmstat

shell> iostat

18.swap 进出量 (内存)

shell> free

19.MySQL 谬误日志

在服务器失常实现初始化后,什么都不会写到谬误日志中,因而任何在该日志中的信息都要引起管理员的留神。
20.InnoDB 表空间信息

InnoDB 仅有的危险状况就是表空间填满 —- 日志不会填满。查看的最好形式就是:show table status; 你能够用任何 InnoDB 表来监督 InnoDB 表的残余空间。

21.QPS 每秒 Query 量

QPS = Questions(or Queries) / seconds

mysql > show /* global */ status like ‘Question’;

22.TPS(每秒事务量)

TPS = (Com_commit + Com_rollback) / seconds

mysql > show status like ‘Com_commit’;

mysql > show status like ‘Com_rollback’;

23.key Buffer 命中率

key_buffer_read_hits = (1-key_reads / key_read_requests) * 100%

key_buffer_write_hits = (1-key_writes / key_write_requests) * 100%

mysql> show status like ‘Key%’;

24.InnoDB Buffer 命中率

Innodb_buffer_read_hits = (1 – innodb_buffer_pool_reads / innodb_buffer_pool_read_requests) * 100%

mysql> show status like ‘innodb_buffer_pool_read%’;

25.Query Cache 命中率

Query_cache_hits = (Qcahce_hits / (Qcache_hits + Qcache_inserts)) * 100%;

mysql> show status like ‘Qcache%’;

26.Table Cache 状态量

mysql> show status like ‘open%’;

27.Thread Cache 命中率

Thread_cache_hits = (1 – Threads_created / connections) * 100%

mysql> show status like ‘Thread%’;

mysql> show status like ‘Connections’;

28. 锁定状态

mysql> show status like ‘%lock%’;

29. 复制延时量

mysql > show slave status

30.Tmp Table 情况 (长期表情况)

mysql > show status like ‘Create_tmp%’;

31.Binlog Cache 应用情况

mysql > show status like ‘Binlog_cache%’;

32.Innodb_log_waits 量

mysql > show status like ‘innodb_log_waits’;

关注公众号:java 宝典

正文完
 0