How do I split a large MySQL backup file into multiple files? [duplicate]

北慕城南 提交于 2019-12-24 12:04:48

问题


I have a 250 MB backup SQL file but the limit on the new hosting is only 100 MB...

Is there a program that let's you split an SQL file into multiple SQL files?


回答1:


You can split a large file in Eclipse. I have tried a 105GB file in Windows successfully:

Just add the MySQLDumpSplitter library to your project: http://dl.bintray.com/verace/MySQLDumpSplitter/jar/

Quick note on how to import:

  • In Eclipse, Right click on your project --> Import
  • Select File System and then Next
  • Browse the path of the jar file and press Ok
  • Select (thick) the MySQLDumpSplitter.jar file and then Finish
  • It will be added to your project and shown in the project folder in Package Explorer in Eclipse
  • Double click on the jar file in Eclipse (in Package Explorer)
  • The MySQL Dump file splitter window opens which you can specify the address of your dump file and proceed with split.



回答2:


It's not pretty (because it just splits on size, not on what is logically in the file) but you can use the unix split tool to accomplish this:

mysqldump mydb | split -b 100m mydbbackup

Make sure to check the man page for split, your copy may or may not accept the 100m size argument. Some need to have the size specified in bytes.

When you go to restore from the file you'll have to use cat to join them all back together.

cat mydbbackup.1 mydbbackup.2 mydbbackup.3 | mysql



回答3:


You can use mysql_export_explode https://github.com/barinascode/mysql-export-explode

<?php 
#Including the class

include 'mysql_export_explode.php';
$export = new mysql_export_explode;

$export->db = 'dataBaseName'; # -- Set your database name
$export->connect('host','user','password'); # -- Connecting to database
$export->rows = array('Id','firstName','Telephone','Address'); # -- Set which fields you want to export
$export->exportTable('myTableName',15); # -- Table name and in few fractions you want to split the table
?>

At the end of the SQL files are created in the directory where the script is executed in the following format
---------------------------------------
myTableName_0.sql
myTableName_1.sql
myTableName_2.sql
...


来源:https://stackoverflow.com/questions/3840848/how-do-i-split-a-large-mysql-backup-file-into-multiple-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!