Import Export SQL file using the command line

Import Export SQL file using the command line

I always forget this so I'm going to save it here. This way I can import the SQL files directly in the terminal.

The following command will import the database:

mysql -u username -p database_name < /file_path/file_name.sql

The above command does not import the triggers and procedures by default.

Use -R and --triggers flags to import the routines and triggers.

Export MySQL database with the below command:

mysqldump -u username -p database_name > /file_path/file_name.sql

Thank you for reading!