Import / Export a database with mysql from terminal

Last updated on 06/12/2017

Import:

- Import a single DB

$ mysql -u [username] -p [my_db_name] < [my_all_db_filename].sql

- Import all DBs

$ mysql -u [username] -p < [my_all_db_filename].sql

Export:

- Export a single database:

$ mysqldump -u [username] -p [my_db_name] > [my_db_filename].sql

- Export multiple databases:

$ mysqldump -u [username] -p --databases [my_db_name_1] [my_db_name_2] > [my_db_filename].sql

- Export all databases:

$ mysqldump -u [username] -p --all-databases > [my_db_filename].sql