How to import and export a mysql database from the command line

Tagged:  

Sometimes you need to use the command line to export or import a mysql database.
Here is how you do it:

mysqldump -u theUser -p theDataBaseName > /path/to/dump/to/export.dump

mysql -u theUser -p theDataBaseName < /path/to/dump/to/import.dump

theUser is your user (usually root)
theDataBaseName is... you guessed it, the database you want to export from or import into

You will be prompted for a password. You could have written the password also after -p but that is a highly insecure way to do it, for several reasons.