Export a MySQL/MariaDB database

Exporting a database can be done very easily from phpMyAdmin/ from your web hosting control panel (cPanel, DirectAdmin, VestaCP etc). But you can also export databases from the command line with the mysqldump utility.

With mysqldump you can export a single database, all databases or a list of databases:

shell> mysqldump [options] db_name [tbl_name …]
shell> mysqldump [options] –databases db_name …
shell> mysqldump [options] –all-databases

mysqldump help page

To backup one database, use the command below. It will save the database as an SQL file.

mysqldump -u db_user -p db_name > db_name.sql

If you are running the commands as root, you don’t need the -u, -p parameters.

root@web [~]# mysqldump admin_wp74 > admin_wp74.sql
root@web [~]# 

If you want to archive the exported database to save space, use:

mysqldump -u db_user -p db_name | gzip > /home/db_name.sql.gz

root@web [~]# mysqldump admin_wp74 | gzip > /root/admin_wp74.sql.gz
root@web [~]#
mariadb logo
MariaDB Logo

Resources:
mysqldump help

Leave a Reply