网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > MySQL
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 49.87.51.253
Old 2015-12-13, 11:01 PM
Nappanee Nappanee is offline
初级会员
 
Join Date: 2011-05-04
Posts: 1
Nappanee 现在声名狼藉
Default 几百万的数据,mysql快速高效创建索引

有一个问题,一张表有3百万条记录,随着时间的增加,记录量会更多,此时查询速度很慢。在创建此表前没有未相应字段添加索引,所以此时需要为表添加索引。但是因为数据量大的原因,索引添加不成功,想了很多办法,终于在短时间内解决了。

  办法如下:

  1、进入mysql界面。mysql -uroot -hlocalhost -plovelive gm;

  2、导出相应表的数据。select * from tab into outfile 'tab.txt'; 此处tab.txt文件在mysql的data目录里

  3、删除相应表的数据,并置第一条记录为0。truncate tab;

  4、创建索引。create index IDX_NAME using BTREE on tab (col);

  索引的方式有:BTREE、RTREE、HASH、FULLTEXT、SPATIAL

  5、导入文件到相应表。load data infile '/mysql/data/tab.txt' into table tab;

Last edited by topvip : 2015-12-14 at 12:05 AM
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 11:12 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.