c++ odbc方式连接mysql产生预处理问题的跟踪
2017-05-31 18:21
721 查看
在程序中如果产生预处理没有关闭,通过mysql二进制日志是很难跟踪的,要跟踪mysql预处理未关闭的情况,可以打开普通日志,在使用python进行数据分析,这样虽然也不能准确定位哪有问题,但是可以排除很多种情况,可以参考一下这个分析脚本
# -*- coding: utf-8 -* # -*- coding: utf-8 -* import time import os file = open("general.log") # TIME_STR = "170401 " TIME_STR = "1704" PREPARE = "Prepare" CLOSE_STMT = "Close stmt" list_sql_once = [] count_prepare = 0 count_stmt = 0 count_line = 0 temp_count_prepare = [] temp_count_stmt = [] temp_total_prepare = 0 temp_total_stmt = 0 dict_count = {} temp_get_sql = [] GET_SQL = 3952278 while 1: line = file.readline() count_line = count_line + 1 list_temp = [] # 统计 第 3*9988行 到 3 *10000 # if count_line < 1*1500 : # continue # if count_line > 150*10000: # break # print "count_line ========================================================",count_line if not line or count_line > 1000*10000: print "count_line ========================================================",count_line break # 找到 prepare 的位置 index_prepare = line.find(PREPARE); index_close_stmt = line.find(CLOSE_STMT); # 获取字典value的值 如果没有则为0 if index_prepare != -1: # 把prepare前面的进程号设置为int值 作为key get_int_str = line[0:index_prepare] try: key_int = int(get_int_str) except Exception as e: get_int_str.rstrip() list_temp = get_int_str.split("\t") # 获取进程号 作为key值 key_int = int(list_temp[1]) if not dict_count.has_key(key_int) : # 如果没有 这个键值{线程号:计数量}对消息,则创建键值对 dict_count[key_int] = 1 else: # 如果有 则 加1 value_int = dict_count[key_int] value_int = value_int + 1 dict_count[key_int] = value_int if key_int == GET_SQL: # 获取 pre 对应的一行sql temp_get_sql.append(line) if index_close_stmt != -1: # 把 close_stmt 前面的进程号设置为int值 作为key get_int_str = line[0:index_close_stmt] try: key_int = int(get_int_str) except Exception as e: get_int_str.rstrip() list_temp = get_int_str.split("\t") key_int = int(list_temp[1]) if not dict_count.has_key(key_int): dict_count[key_int] = -1 print "--------------------here" else: # print "key_int==", key_int value_int = dict_count[key_int] value_int = value_int - 1 dict_count[key_int] = value_int if key_int == GET_SQL: temp_get_sql.append(line) for ele in dict_count: if dict_count[ele] != 0: print "key==",ele,"value==", dict_count[ele] print "-----------------------------------------------------------------" try: fout = open("test1.txt", "w") except IOError: print "Error: open file failed." count_ele = 0 for ele in temp_get_sql: line = str(ele) + "\n" fout.write(line) fout.close() # print "count_ele == ", count_ele only_ele_list = [] try: fout2 = open("test2.txt", "w") except IOError: print "Error: open file failed." for ele in temp_get_sql: if ele not in only_ele_list: only_ele_list.append(ele) # 把查询到的不重复sql存放到 文本文件中 for ele in only_ele_list: line = str(ele) + "\n" fout2.write(line) fout2.close()
相关文章推荐
- 关于c++连接mysql产生8小时连接失效的问题
- PHP连接MySQL方式比较问题
- vs2008下MFC中采用ado连接MySQL(ODBC、非ODBC或C API方式)
- Delphi XE8中的DBExpress使用ODBC方式连接MySQL 5.6.24 X64!!!!
- vs2008下MFC中采用ado连接MySQL(ODBC、非ODBC或C API方式)
- Windows上C++连接MySql的问题
- C++连接MySQL(二):环境配置和实例 使用api方式
- Mysql ODBC 连接Mysql参数的问题
- Delphi XE8中的DBExpress使用ODBC方式连接MySQL 5.6.24 X64!!!!
- c++使用mysql的api连接相关问题
- MySQLConnector/C++连接方式二
- C/C++中调用api设置mysql连接的编码方式
- VS2012 使用MySql的API函数连接数据库(成功), 以及使用mysql-connector-c++-1.1.3遇到的问题!
- 《关于在MFC中使用ODBC方式连接数据库可能出现的问题》第一篇
- c++ 连接mysql,中文输入的问题
- 设置、调用-C/C++中调用api设置mysql连接的编码方式-by小雨
- C/C++中调用api设置mysql连接的编码方式
- java 通过用jdbc:odbc方式连接MSSQL2008 Connection refused: connect 问题处理
- 使用MySql自带的库进行数据库连接时可能产生的一些问题
- MFC通过ODBC方式连接mysql