Freelance writing


Content strategy

How to backup a WordPress database without plugins or phpMyAdmin

December 1, 2018

Two months ago I was convinced it was impossible to backup a WordPress database through the command line. Anyone who suggested otherwise was lying, or a wizard.

However I no longer believe this to be sorcery:

So here it is.

How to export a MySQL database using the command line in Ubuntu

I access my Ubuntu server with Putty.

Navigate to the folder where the backup file will go with the cd command.

Then if you know which database you’re using already use this command to create the backup:
mysqldump -u username -p database_name > backup_name.sql

You’ll be prompted for your password. Type it and you’re good to go.


If you need to remind yourself of the database name you can look at your site’s wp-config.php file and find this:
/** The name of the database for WordPress */
define('DB_NAME', 'database_name');

Here, database_name is what you’re looking for.

If you want to see the database before backing it up, open MySQL once you’re logged into Ubuntu:
mysql -u root -p

Then list your databases: show databases;

This will list them all, and you’ll be able to verify the one you’re looking for is there.