How to Backup MySQL Database on Command Line Updated on April 23, 2020 by Christopher Maiorana 1 Minutes, 31 Seconds to Read For all of your SQL backup needs, the mysqldump command does everything for you. This handy utility creates a plain text file with the SQL commands needed to re-create the database. How to backup a single database on the command lineHow to backup all databases on the command lineHow to backup a WordPress database on command Line This makes it much easier to transfer databases to other servers as well as creating backups. How To Backup a Single Database On The Command Line In order to backup a single database, you’ll just need to run this statement at your command prompt: mysqldump > dump.sql In this case, “dump.sql” is the backup file you want to generate. You can change that filename to whatever you want. How To Backup All Databases on The Command Line If you maintain multiple sites with multiple databases, you can also back them all up with one command: mysqldump --all-databases > dump.sql How To Backup a WordPress Database On Command Line Using the command line is simply faster and more efficient. For example, with two commands, you can locate and backup a WordPress database. First, make sure you change directories into the root of the WordPress site (where the core files are located). Then drop this command: dw(){ dr="${1-$PWD}"; config="${dr%/}/wp-config.php"; db=$(grep "DB_NAME" $config|cut -d\' -f4); usr=$(grep "DB_USER" $config|cut -d\' -f4); pw=$(grep "DB_PASSWORD" $config|cut -d\' -f4); pre=$(grep "table_prefix" $config|cut -d\' -f2);}; dw Now the database name and user/password information are stored in variables that will be used when you run the next command: mysqldump -Q --add-drop-table --routines -h${host-localhost} -p"$pw" -u$usr $db So with two commands you now have a backup of the WordPress database. Share this Article CM Christopher Maiorana Content Writer II Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog. More Articles by Christopher Related Articles Understanding Linux Operating Systems How to Install Python 3.9 on CentOS 7 Speed Up grep Searches with LC_ALL=C How To Install RubyGems On Linux unrar and rar Commands 5 Ways to Find a File in Linux Setting Your PHP Settings in Command Line How to Check the Memory Usage on Linux How to Send Files to the Trash Can in Linux with Gio Trash How to Merge PDF Files in the Linux Terminal