May 25, 2017

How to Backup and Restore a MySQL Database

MySQL Logo

Backing up MySQL databases is an area that is often forgotten. The only time you probably think of backing up your MySQL data is when you change your web host or switch to an other database server. With this instruction we will show you how easy it is to backup and restore a MySQL database.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Database Backup with mysqldump

Backup your database with the following command line. Please replace:

  • -hlocalhost with your server name
  • -uroot with the MySQL user
  • -proot with the password of the MySQL user
  • database with the name of the database
  • backup.sql with your prefered backup file.

There is no need to add a semicolon at the end of the line.

mysqldump -hlocalhost -uroot -proot database > backup.sql

Restore the database with mysql

Restore your database with the following command line. Please replace:

  • -hlocalhost with your server name
  • -uroot with the MySQL user
  • -proot with the password of the MySQL user
  • database with the name of the database
  • backup.sql with your prefered backup file.
mysql -hlocalhost -uroot -proot database < backup.sql

There is no need to add a semicolon at the end of the line.

Comments

  1. You have written a great website.

  2. cardiofrequencemetre sans ceinture says:

    My developer is trying to convince me to move to .net from PHP.

    I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on several websites for about a year and am nervous about
    switching to another platform. I have heard excellent things about blogengine.
    net. Is there a way I can import all my wordpress posts into it?

    Any kind of help would be greatly appreciated!

  3. MySQL is scary first time, after you’re familiar with it it’s a breeze!

Speak Your Mind