回答
可能不是代码..
关闭所有其他应用程序,确保没有其他任何东西占用你的CPU使用率,没有恶意软件?获得更快的电脑?
如果您可以告诉我们您正在使用的环境设置等,这将有所帮助。它可能是一些涉及你的网络,你的服务器等等的东西。
有些东西告诉我,如果它是1000万行,它是具有大量流量的高容量服务器,或者是数据服务器的一部分一个非常便宜的公司,没有其他的事情发生。这看起来更像是一个案例“我需要更多的权力,Scotty!”。 – 2011-03-14 18:08:48
哈哈!是的,也许,thx指出了:) – 2011-03-14 18:21:29
以下内容非常快,需要6分钟以上的1000万行,但示例表中的字段和索引数量少于生产表,因此如果您决定使用它,则需要花费更长的时间!
注意:该示例是在Windows操作系统上完成的,因此您必须更改路径名和\ r \ n以符合linux标准!
这里是我现有的表(InnoDB引擎OFC):
drop table if exists customers;
create table customers
(
customer_id int unsigned not null auto_increment primary key,
name varchar(255) not null,
country_id tinyint unsigned not null default 0,
key (country_id)
)
engine=innodb;
mysql> select count(*) from customers;
+----------+
| count(*) |
+----------+
| 10000000 |
+----------+
1 row in set (1.78 sec)
创建,其中包括您所需要的新的字段的表的新版本:
drop table if exists customers_new;
create table customers_new
(
customer_id int unsigned not null auto_increment primary key,
name varchar(255) not null,
country_id tinyint unsigned not null default 0,
split tinyint not null default 0,
key (country_id)
)
engine=innodb;
出口数据从旧客户表中按PK订单转换为csv格式:
select * into outfile 'c:\\customers.dat'
fields terminated by '|' optionally enclosed by '"'
lines terminated by '\r\n'
from customers order by customer_id;
Query OK, 10000000 rows affected (17.39 sec)
负荷customer.dat文件到新的客户表:
truncate table customers_new;
set autocommit = 0;
load data infile 'c:\\customers.dat'
into table customers_new
fields terminated by '|' optionally enclosed by '"'
lines terminated by '\r\n'
(
customer_id,
name,
country_id,
@dummy -- represents the new split field
)
set
name = nullif(name,'');
commit;
Query OK, 10000000 rows affected (6 min 0.14 sec)
检查,看是否一切正常
select * from customers_new order by customer_id desc limit 1;
+-------------+-------------------+------------+-------+
| customer_id | name | country_id | split |
+-------------+-------------------+------------+-------+
| 10000000 | customer 10000000 | 218 | 0 |
+-------------+-------------------+------------+-------+
1 row in set (0.00 sec)
insert into customers_new (name, country_id, split) values ('f00',1,1);
Query OK, 1 row affected (0.07 sec)
select * from customers_new order by customer_id desc limit 1;
+-------------+------+------------+-------+
| customer_id | name | country_id | split |
+-------------+------+------------+-------+
| 10000001 | f00 | 1 | 1 |
+-------------+------+------------+-------+
1 row in set (0.00 sec)
删除旧表,并重新命名新:
drop table customers;
Query OK, 0 rows affected (0.18 sec)
rename table customers_new to customers;
Query OK, 0 rows affected (0.05 sec)
select * from customers order by customer_id desc limit 1;
+-------------+------+------------+-------+
| customer_id | name | country_id | split |
+-------------+------+------------+-------+
| 10000001 | f00 | 1 | 1 |
+-------------+------+------------+-------+
1 row in set (0.00 sec)
这就是所有人!
- 1. MySQL缓慢查询
- 2. MySQL缓慢查询
- 3. MySQL缓慢查询
- 4. MySQL慢查询日志 - 缓慢多慢?
- 5. MySQL缓慢查询失败
- 6. mysql查询运行缓慢
- 7. 缓慢的MySQL SELECT查询
- 8. MySql缓慢并发查询
- 9. MySQL缓慢查询优化
- 10. MySQL缓慢查询'COUNT'
- 11. MySQL缓慢查询和memcached
- 12. MySQL查询随机缓慢
- 13. MySQL缓慢子查询
- 14. 缓慢的MySQL查询
- 15. MySQL查询缓慢运行
- 16. MySQL缓慢查询〜10秒
- 17. 缓慢*初始* mysql查询
- 18. MySQL查询变得缓慢
- 19. MySQL加入缓慢查询
- 20. 缓慢的mysql查询
- 21. MYSQL GROUP BY - 缓慢查询
- 22. 缓慢UNION查询 - MySQL
- 23. mysql查询查询速度缓慢
- 24. 缓慢的子查询mysql查询
- 25. 首先MySQL缓慢查询,快速查询子查询
- 26. Mysql - 缓慢的查询输出
- 27. 缓慢的MySQL查询和CPU限制
- 28. 缓慢MySQL查询不使用filesort
- 29. MySQL UNION语句缓慢查询
- 30. 缓慢的mysql查询Like /匹配
你目前在这个服务器上有什么负载? – wlk 2011-03-14 18:00:52
另外,桌上有多少个索引......如果你有很多索引,它也必须重建所有的索引页面......一千万没有什么可以打喷嚏来首先改变表格,然后重新索引影响。 – DRapp 2011-03-14 18:17:00
您正在使用哪种存储引擎? MyISAM数据? InnoDB的?您可以更改一些设置以使其更快,但它们取决于存储引擎。 – 2011-03-14 18:41:42