Name

mysqldump

Synopsis

mysqldump [options] --all-databases
mysqldump [options] --databases database [database ...]
mysqldump [options] database [table]

This utility exports MySQL data and table structures. Typically, you use it to make backups of databases or to copy databases from one server to another. You can run it on an active server. For consistency of data between tables, the tables should be locked (see the --lock-tables option) or the mysqld daemon should be shutdown.

There are three syntaxes for this utility. The first method shown makes a backup of all databases for the server. The second method backs up specific databases, named in a space-separated list, including all tables in each database. The third method backs up specific tables of a specific database.

Here is an example using the first method, backing up all databases on the server:

mysqldump --host=russell.dyerhouse.com --user=russell --password \
   --lock-tables --all-databases > /tmp/workrequests.sql

Because the backup is being run from a remote server (i.e., not the localhost), the --host option is given with a domain name address for the host. An IP address could be given instead. Making a backup remotely like this will work only if the host grants the necessary privileges to user russell with the host from which mysqldump is running. The example redirects the results with a greater-than sign to a text file.

To make a backup of a specific database, use the second syntax for this utility. Enter something like the following ...

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.