Quick reference for importing and exporting a MySQL database from the terminal.
Import a database
Use the mysql client to load a dump file into an existing database:
mysql -u username -p database_name < /path/to/file.sql-uspecifies the user;-pprompts for the password.- Include
-h <host>or-P <port>if needed.
Export a database
Create a dump with mysqldump:
mysqldump -u username -p database_name > /path/to/file.sql- Add
-h <host>or-P <port>as required. - To include routines and triggers, use:
mysqldump -u username -p -R --triggers database_name > /path/to/file.sql
That’s it—two commands to move data in and out quickly.