mysql slow query---pt-query-digest----db structure consistency,monitor table records before and after transaction.

将数据库脚本纳入版本管理是很必要的,尤其对于需要在客户那里部署升级的系统。

对于Python Django等框架,由于数据库是通过Model生成的,因此框架本身包括数据库升级工具,并通过代码版本间接管理了数据库脚本。
对于直接通过数据库脚本来维护数据库schema和数据的框架,或者使用DbMaintain / Liquibase工具,它们提供了一些工具来跟踪当前数据库的版本并可以自动升级、回退、比较数据库等。(DbMaintain使用SQL,相比之下更自然一些,建议使用。)

DbMaintain
http://dbmaintain.org/overview.html
https://github.com/DbMaintain/dbmaintain


Liquibase
http://www.liquibase.org



mysqldump --skip-comments --skip-extended-insert -d --no-data -u root -p dbName1>file1.sql mysqldump --skip-comments --skip-extended-insert -d --no-data -u root -p dbName2>file2.sql diff file1.sql file2.sql

monitor table records before and after transaction.

SELECT table_name, table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '**YOUR SCHEMA**';


mysqldump --skip-comments --skip-extended-insert -d --no-data -u webuser01 -p -S /tmp/mysql3306.sock uexercise>ue.sql

http://blog.csdn.net/lanbingkafei/article/details/8525187

high performance MySQL笔记:

孔子说“工欲善其事,必先利其器”, 今天就介绍一下percona toolkit中的pt-query-digest。

下载地址:

http://www.percona.com/software/percona-toolkit/

官方文档:

http://www.percona.com/doc/percona-toolkit/pt-query-digest.html

请先确定在my.ini中打开了mysql的slow_query_log,并且保证long_query_time参数设置得很合理。

[sql] view plain copy
 
  1.    
  2. # Log slow queries. Slow queries are queries which take more than the  
  3. # amount OF TIME defined IN "long_query_time" OR which do NOT USE  
  4. # indexes well, IF log_short_format IS NOT enabled. It IS normally good idea  
  5. TO have this turned ON IF you frequently ADD NEW queries TO the  
  6. # system.  
  7. slow_query_log  
  8.    
  9. ALL queries taking more than this amount OF TIME (IN seconds) will be  
  10. # trated AS slow. Do NOT USE "1" AS a VALUE here, AS this will RESULT IN  
  11. # even very fast queries being logged FROM TIME TO TIME (AS MySQL  
  12. # currently measures TIME WITH SECOND accuracy ONLY).  
  13. long_query_time = 2  

pt-query-digest是一个perl脚本,只需下载即可。

[root@sso bianxuehui]# wget percona.com/get/pt-query-digest 
[root@sso bianxuehui]# file pt-query-digest 
pt-query-digest: a perl script text executable
[root@sso bianxuehui]# ll  pt-query-digest
-rw-r--r-- 1 root root 499727 09-02 00:01 pt-query-digest
[root@test_dx modify]# chmod u+x pt-query-digest 

使用如下,如果slow log够大的话,会消耗相当多的cpu和内存,所以最好把slow log和pt-query-digest放到其它的server上面运行。

[root@test_dx bianxuehui]# ./pt-query-digest  slow.log  >digest.log
原文地址:https://www.cnblogs.com/SZLLQ2000/p/6006881.html