How can I backup and restore a MySQL database?

Create backup

To create a backup of a MySQL database, you usually use the tool "mysqldump". Save a backup of a database to a *.sql file:

root@server:~# mysqldump -u username -p database name > /path/to/backup.sql

User for database access
database name
Database to backup
Path to backup file

The tool "mysqldump" is started with the usual parameters and the result is saved in a *.sql file. With this file you are able to restore your databases on this or another server.

Restoring a backup

root@server:~# mysql -u username -p database name < /path/to/backup.sql

If the target database does not yet exist, it must be created beforehand. To do this, log on to the MySQL console and create the database:

root@server:~# mysql -u root -p
Enter Password:

mysql> CREATE DATABASE ‘database name’;

You cannot comment on this entry