Need help? Chat now!

Hostwinds Tutorials

Search results for:


Table of Contents


Backing Up A Single Database
Backing Up Multiple Databases
Backing Up All Databases
Restoring Database(s)

Backup And Restore MySQL Databases Using mysqldump

Tags: MySQL 

Backing Up A Single Database
Backing Up Multiple Databases
Backing Up All Databases
Restoring Database(s)

mysqldump lets you quickly and efficiently take a backup of a single database, multiple databases, or even all of the databases on your server. This requires shell access to the server you wish to perform the commands on and the MySQL login credentials for your user(s).

SSH access is not allowed on our shared or business shared services.

Backing Up A Single Database

To back-up, a single database, log in via SSH and run the following commands.

Usage:

mysqldump -u user -p[user_pass] [database_name] > dumpfile.sql

Example:

mysqldump -u root -pABC123 exampledb > exampledbdump.sql

The filepath for your database (.sql) backup will be your current working directory. You may use an absolute path as well, such as /root/exampledbdump.sql

Backing Up Multiple Databases

If you wish to backup two or more databases, you'll need to specify –databases followed by the names of the databases you want to backup. Remember that the database user must have privileges to access the database that is being backed up.

Usage:

mysqldump -u user -p[user_pass] –databases [database_name] [database_name] [database_name] > dumpfile.sql

Example:

mysqldump -u root -pABC123 –databases exampledb sampledb testdb > exampledb_sampledblsql_testdb.sql

Backing Up All Databases

Run the following command to back-up all current databases

Usage:

mysqldump -u user -p[user_pass] –all-databases > all-dbs.sql

Example:

mysqldump -u root -pABC123 –all-databases > all-dbs.sql

Restoring Database(s)

Restore databases running the following command

Usage:

mysql -u user -p[user_pass] [database_name] < dumpfile.sql

Example:

mysql -u root -pABC123 exampledb < exampledbdump.sql

Written by Michael Brower  /  September 28, 2017