Import SQL file using the command line in MySQL?

Import a .sql file using the command line. Replace the username and database name and the sql file with the actual values.

mysql -u username -p database_name < file.sql

For this to work, an empty database must exist. If the database does not exist, then you must create an empty database and then run the command above to import.