Import a Large File MySQL

Every once in a while I have to import a large SQL file and have to look up the best way to do it. This method has worked for me consistently so far so I am posting it here so that I don't forget.

mysql -u root -p  

Set network buffer length to a large byte number

SET global net_buffer_length=1000000;  

Set maximum allowed packet size to a large byte number

SET global max_allowed_packet=1000000000;  

Disable foreign key checking to avoid delays,errors and unwanted behavior

SET foreign_key_checks = 0;  

Import your sql dump file

SOURCE file.sql  

Remember to enable foreign key checks when procedure is complete

SET foreign_key_checks = 1;