查看MySQL数据存储路径信息
分号不能掉
show variables like '%datadir%';
查询表的每个字段详细信息
SELECT*FROMinformation_schema.COLUMNSWHEREtable_name = 'ivr_stay_time_statistic'AND table_schema = 'ngcc_db'ORDER BYordinal_position
MySQL创建索引后查询效率还是很慢
在10W条数据中如下查询语句很慢
SELECTt.id,t.firstCallId,t.secondCallId,t.calledNum,t.callerNum,t.firstCallTime,t1.hookNodeId,t.secondCallTime,t2.hookNodeIdFROM repeat_call_temp tLEFT JOIN ivr_node_track_record_list AS t1 ON t.firstCallId = t1.callIdLEFT JOIN ivr_node_track_record_list AS t2 ON t.secondCallId = t2.callIdWHERE t.firstCallTime between '2020-04-14 00:00:00' AND '2020-04-14 23:59:59'
添加 EXPLAIN 关键字模拟Mysql优化器是如何执行SQL查询语句的,从而知道Mysql是如何处理你的SQL语句的。分析你的查询语句或是表结构的性能瓶颈。
EXPLAINSELECTt.id,t.firstCallId,t.secondCallId,t.calledNum,t.callerNum,t.firstCallTime,t1.hookNodeId,t.secondCallTime,t2.hookNodeIdFROM repeat_call_temp tLEFT JOIN ivr_node_track_record_list AS t1 ON t.firstCallId = t1.callIdLEFT JOIN ivr_node_track_record_list AS t2 ON t.secondCallId = t2.callIdWHERE t.firstCallTime between '2020-04-14 00:00:00' AND '2020-04-14 23:59:59'
返回如下内容,可以看到tye列显示的是ALL表示全表扫描没有用到索引
上述问题可能是因为表中字段的字符集编码不一致导致的。
输入如下语句查看表中的字段信息:
SHOW FULL COLUMNS FROM repeat_call_temp;SHOW FULL COLUMNS FROM ivr_node_track_record_list;
返回如下信息:
表:repeat_call_temp
表:ivr_node_track_record_list
可以看到关联条件中的callId、firstCallId、secondCallId之间的字符编码不同
输入如下语句修改字符编码:
ALTER TABLE ivr_node_track_record_list CHANGE callId callId VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin
表:ivr_node_track_record_list 的callId字段的字符集编码已经修改成 utf8_bin 
type从ALL变成了ref ,rows也变小了,重新执行查询语句速度会提升好几倍
