This article shows how to backup WordPress database using MySQL command line. MySQLdump command line is used to perform various backup operations in MySQL databases. Mysqldump is a command-line client program which is used to dump local or remote MySQL database or collection of databases for backup into a single flat file.
Backup WordPress Database Using MySQL Command Line
The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with all the SQL commands needed to recreate the database from scratch. The process is quick and easy. To take a backup of MySQL database or databases, the database must exist in the database server and you must have access to it. The format of the command would be.
# mysqldump -u [username] –p[password] [database_name] > [dump_file.sql]
The parameters of the said command as follows.
- [username] : A valid MySQL username.
- [password] : A valid MySQL password for the user.
- [database_name] : A valid Database name you want to take backup.
- [dump_file.sql] : The name of backup dump file you want to generate.
Backup a Single MySQL Database
It’s very easy to take a backup of single database. Below is the command line which is used for backup. The command will dump database [mustbeweb] structure with data into a single dump file called mustbeweb.sql.
# mysqldump -u root mustbeweb mustbeweb > mustbeweb.sql
Backup Multiple MySQL Databases
If you want to take backup of multiple databases, run the following command. The following example command takes a backup of databases [mustbeweb, wordpress] structure and data into a single file called mustbeweb_wordpress.sql.
# mysqldump -u root -ptecmint --databases mustbewed wordpress > mustbeweb_wordpress.sql
Backup All MySQL Databases
It’s easy to take backup of all your database with a single command line with option –all-database. The following command takes the backup of all databases of mustbeweb with their structure and data into a file called all-databases.sql.
# mysqldump -u root -mustbeweb --all-databases > all-databases.sql
Use the mysqldump utility to create a backup of your database.
- Open up a Windows command prompt.
- Click Start > Run
- Enter “cmd” into the dialog box and click the “OK” button.
- Change the directory to the following to access the mysqldump utility.
- cd C:\Program Files\MySQL\MySQL Server 5.5\bin
- Create a dump of your current mysql database or table (do not include the bracket symbols [ ] in your commands).
- Run the mysqldump.exe program using the following arguments:
- mysqldump.exe –e –u[username] -p[password] -h[hostname] [database name] > C:\[filename].sql
- If you supplied all the arguments properly, the program will connect to your current mysql server and create a dump of your whole database in the directory you specified in your C:\ directory. There is no message that will indicate the dump has been completed, the text cursor will simply move to the next line.
There are many other features and commands available if you would like to dig a little deeper into this useful utility, including backup MySQL databases structure only, backup MySQL database data only, backup single table of database, backup multiple tables of database, backup remote MySQL database and much more.