Try this:
mysqldump -u root -p databasename > dbbackup.sql
Then to restore:
mysql -u root -p databasename < dbbackup.sql
The options are as follows.
-u
indicates the username (here I am using root - the administrator user, but you can use another user with rights to the database)
-p
indicates the prompt for a password (this is the password that is associated with the user you specified above). After pressing enter on the mysqldump command, you will be prompted to enter a password.
databasename
is the name of your database of course
dbbackup.sql
is the name of the file to save your exported database to (you can rename it to whatever you want
Notice in both commands the difference between >
and <
. These are redirection operators.
>
indicates that you are writing to a file. <
indicates you are reading from a file. You don't want to accidentally use >
for the last command because you could end up writing over your backup file.