Export a large MySQL table as multiple smaller files

前端 未结 7 1331
你的背包
你的背包 2020-12-28 09:26

I have a very large MySQL table on my local dev server: over 8 million rows of data. I loaded the table successfully using LOAD DATA INFILE.

I now wish to export thi

7条回答
  •  一向
    一向 (楼主)
    2020-12-28 10:22

    Take a look at mysqldump

    Your lines should be (from terminal):

    export to backupfile.sql from db_name in your mysql:

    mysqldump -u user -p db_name > backupfile.sql
    

    import from backupfile to db_name in your mysql:

    mysql -u user -p db_name < backupfile.sql
    

    You have two options in order to split the information:

    1. Split the output text file into smaller files (as many as you need, many tools to do this, e.g. split).
    2. Export one table each time using the option to add a table name after the db_name, like so:

      mysqldump -u user -p db_name table_name > backupfile_table_name.sql

    Compressing the file(s) (a text file) is very efficient and can minimize it to about 20%-30% of it's original size.

    Copying the files to remote servers should be done with scp (secure copy) and interaction should take place with ssh (usually).

    Good luck.

提交回复
热议问题