Import large sql file django

2019-08-22 02:15发布

问题:

I have a sql file that has ~ 42,000 INSERT statements

I wondered what the best, and quickest way to import this into an existing table?

I am using django and have just installed South too

Any suggestions are welcome.

I originally thought - just bypass models.py and directly connect through Sequel Pro for mac, but something tells me this won't make south or django happy.

回答1:

Generally this is done using a transaction. Edit the file having all the INSERTs. Add a line on top and bottom:

BEGIN TRANSACTION;
-- all insert statements go here
COMMIT;

Now once you login to MySQL from the command line execute

mysql> source file_name

See here for details.