创建测试表
# 创建测试表test
create table test(title varchar(10));
# 使用编辑器插入十万条数据
form pymysql import connect
def main():
conn = connect(hose='127.0.9.2',port=3306 ,database='student',user='root',password='root',charset='utf8')
cursor = conn.cursor()
for i in range(10000);
cursor.execute( "insert into test values( 'tg-%d ' )" % i)
conn.commit()
if __name__ == '__main__':
main()
查询表
·开启运行时间监测
set profiling=1;
· 查找第1万条数据tg-99999
select * from test where title='tg-99999';
· 查看执行的时间
show profiles;
· 为表title_index的title列创建索引
create index title_index on test(title(10));
·执行查询语句
select * from test where title='ha-99999';
·再次查看执行的时间
show profiles;