improve speed of mysql import

前端 未结 9 1547
無奈伤痛
無奈伤痛 2021-01-31 14:26

I have large database of 22GB. I used to take backup with mysqldump command in a gzip format.

When i extract the gz file it produces the

9条回答
  •  走了就别回头了
    2021-01-31 15:13

    I've had to deal with the same issue. I've found using mysqldump to output to a CSV file (like this):

    mysqldump -u [username] -p -t -T/path/to/db/directory [database] --fields-enclosed-by=\" --fields-terminated-by=,
    

    and then importing that data using the LOAD DATA INFILE query from within the mysql client (like this):

    LOAD DATA FROM INFILE /path/to/db/directory/table.csv INTO TABLE FIELDS TERMINATED BY ',';
    

    to be about an order of magnitude faster than just executing the SQL queries containing the data. Of course, it's also dependent on the tables being already created (and empty).

    You can of course do that as well by exporting and then importing your empty schema first.

提交回复
热议问题