监控mysql

显示进程状态变量

mysql> show variables like '%thread%';
+----------------------------+---------------------------+
| Variable_name | Value |
+----------------------------+---------------------------+
| innodb_file_io_threads | 4 |
| innodb_thread_concurrency | 8 |
| innodb_thread_sleep_delay | 10000 |
| max_delayed_threads | 20 |
| max_insert_delayed_threads | 20 |
| myisam_repair_threads | 1 |
| pseudo_thread_id | 2 |
| thread_cache_size | 0 |
| thread_handling | one-thread-per-connection |
| thread_stack | 262144 |
+----------------------------+---------------------------+

query cache

如果你使用的是myisam存储引擎的,query cache是一个最终的性能,他允许服务器在内存中缓存频繁使用的查询语句和查询结果,因此一个查询运行的越频繁,这个查询结果就越可能从缓存中得到,显然,从内存中读取数据比从硬盘上读取数据要快的多

通过have_query_cache变量查询query cache是否可用;

mysql> show variables like '%query_cache%';
+------------------------------+---------+
| Variable_name | Value |
+------------------------------+---------+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 0 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
+------------------------------+---------+

have_query_cache 变量仅仅表示这个特性可用,query_cache_size 这个变量值为0,它将迅速关闭query cache ;

Query cache状态变量

mysql> show status like '%Qcache%';
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Qcache_free_blocks | 0 |
| Qcache_free_memory | 0 |
| Qcache_hits | 0 |
| Qcache_inserts | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 0 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 0 |
+-------------------------+-------+
8 rows in set (0.00 sec)

可以定期使用flush query cache 这个命令重整 querycache

,这样不会删除内存中的结果,但是允许重新组织内存以更好地3使用内存;

mysql> flush query cache;
Query OK, 0 rows affected (0.00 sec)

mysql性能

使用explain

mysql> explain select * from student where id>'901'\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: student
type: ALL
possible_keys: PRIMARY
key: NULL
key_len: NULL
ref: NULL
rows: 5
Extra: Using where
1 row in set (0.00 sec)

看到该查询已经检测到了索引,但key为NULL,没有使用索引。

删除范围查询看看结果:

mysql> explain select * from student where id='901'\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: student
type: const
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: const
rows: 1
Extra:
1 row in set (0.00 sec)

使用analyze table

可以为myisam和Innodb表更新主健分布,但不是使用于所有的引擎。

分析表并更新主健分布

mysql> analyze table student;
+----------------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+----------------+---------+----------+----------+
| school.student | analyze | status | OK |
+----------------+---------+----------+----------+
1 row in set (0.00 sec)

通过show index查看索引的状态:

mysql> show index from student\G;
*************************** 1. row ***************************
Table: student
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
1 row in set (0.00 sec)

无论表何时发生重大的更新(例如批量加载数据),都应该执行这个命令,在这个操作过程中,系统必须要先给这个表设定一个锁。

使用optimize table

被频繁更新的表将很快变的支离破碎,并取决于存储引擎的不同,将会出现不同程度 的闲置空间和不理想的存储结构;

使用optimize table命令可以重构一个或多个表的数据结构;

mysql> optimize table student\G
*************************** 1. row ***************************
Table: school.student
Op: optimize
Msg_type: status
Msg_text: OK
1 row in set (0.00 sec)

无论表何时发生重大更新(例如大量删除和插入),都应该执行这个命令,这个操作用于优化数据元素排列结构,而且它比预期运行的时间长,这个操作适合在低负载时运行;

最新文章

  1. Create Volume 操作(Part I) - 每天5分钟玩转 OpenStack(50)
  2. iOS歌词逐渐变色动画
  3. servlet内置对象
  4. Select2个人使用总结
  5. JavaScript的面向对象编程(OOP)(一)——类
  6. cmd运行的程序的工作目录
  7. eclipse插件开发--获取当前项目路径
  8. COM/ATL 资料收集
  9. Base64加密
  10. debian7安装oracle11g
  11. [原创]安卓使用Termux做渗透测试(演示sqlmap安装,并附上一个神器)
  12. hdu_5589_Tree(莫队+字典树)
  13. 洛谷 P1908 逆序对
  14. SQL Server 连接(内连接,外连接,完全连接,交叉连接,联合)
  15. 记录片宇宙之the secret of the sun
  16. P3412 仓鼠找sugar II
  17. Windbg命令学习15(bp bm bu bl bc ba断点)
  18. java 加密
  19. k8s oomkilled超出容器的内存限制
  20. Python并行(parallel)之谈

热门文章

  1. nginx代理,负载均衡
  2. 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_06.入门案例的流程总结
  3. STM32 PWM注意事项
  4. Web03_JavaScript
  5. java:反射(Hibernate的雏形)
  6. java里null强转为某个类会报错吗?
  7. WebLogic下Argument(s) "type" can't be null.
  8. shadow使用方法
  9. 【FICO系列】SAP 参数(条件表)灵活配置GS01/GS02/GS03
  10. Python学习之协程