Reputation: 38852
I am using MySQL v5.1.
My simple scenario is that I would like to import a large amount of data from a table in one database to another table in another database. And the table in another database (to where the data is going to be inserted) will be truncated first.
To be detailed, Say I have two databases, named 'db_one' and 'db_two' respectively.
db_one has a table named db_one_cars
which contains 6,000,000 records (which is a big amount of data). While db_two has a table named db_two_cars
which contains also a big amount of data.
I am going to firstly remove all the data in db_two_cars
(truncate the table), then import all the data from db_one_cars
to db_two_cars
. (Note: the two tables are in two databases respectively).
So, I created a sql file with content like following:
TRUNCATE TABLE db_two_cars;
ALTER TABLE db_two_cars DISABLE KEYS;
INSERT INTO db_two_cars (car_id, name, customer, company_name)
SELECT id, CONCAT('c-', name), customer, company_name FROM db_one.db_one_cars;
ALTER TABLE db_two_cars ENABLE KEYS;
both db_one_cars and db_two_cars tables are InnoDB table and have the same structure, car_id
is used as primary key
, company_name
is used as multi-column key
, customer
is used as multi-column key
.
I would like to speed up this large amount of data importing, and also want a good performance to query the table after improting data.
my questions:
OPTIMIZE TABLE db_two_cars
at the end of my SQL statement? and why? (will it improve the performance? I am merely inserting data)ALTER TABLE db_two_cars PACK_KEYS = 0 ?
and why? (will it improve the performance)P.S. The performance I mean includes speed up the data importing and good performance for future data querying
Upvotes: 0
Views: 244