There are many cases where you will want to dump a MySQL database. Examples include: backing up a website, migrating a website to a new server, moving from a development machine to a production server, and more.

Simply run this command, substituting the USERNAME, DATABASE_NAME, and FILENAME with your info. When you run this command, it will prompt you for the MySQL password for the USERNAME you provided:

mysqldump -u USERNAME -p DATABASE_NAME > FILENAME.sql

As a final note, before running this command I like to cd into the folder where I will save the .sql file. This way, I do not have to provide a path to the mysqldump command, and I can inspect the output .sql file immediately.