How to import large SQL files into MySQL using the command line

Import large SQL databases into MySQL

As a rule, most WordPress sites have small databases — and by “small” I mean under 100 MB. But when it comes to e-commerce stores or news portals, the database can easily grow to several hundred megabytes. Trying to import a file that size through phpMyAdmin usually ends with an error.

Problem: How to import large SQL files into MySQL.

Solution: Use the command line:

mysql -h 127.0.0.1 -u username -p database_name < /path/to/"database (1).sql"

NOTE: If the filename contains spaces, wrap it in quotes as shown above.

For exporting a database, use mysqldump:

mysqldump -h 127.0.0.1 -u username -p database_name > /path/to/"database (1).sql"