Dumping Data in SQL Format with
mysqldump
626
• To make a copy of a database that you can use without changing the original data.
• To test potential upgrade incompatibilities.
mysqldump
produces two types of output, depending on whether the
--tab
[305]
option is given:
• Without
--tab
[305]
,
mysqldump
writes SQL statements to the standard output. This output
consists of
CREATE
statements to create dumped objects (databases, tables, stored routines, and
so forth), and
INSERT
statements to load data into tables. The output can be saved in a file and
reloaded later using
mysql
to recreate the dumped objects. Options are available to modify the
format of the SQL statements, and to control which objects are dumped.
• With
--tab
[305]
,
mysqldump
produces two output files for each dumped table. The server writes
one file as tab-delimited text, one line per table row. This file is named
tbl_name.txt
in the output
directory. The server also sends a
CREATE TABLE
statement for the table to
mysqldump
, which
writes it as a file named
tbl_name.sql
in the output directory.
7.4.1. Dumping Data in SQL Format with
mysqldump
This section describes how to use
mysqldump
to create SQL-format dump files. For information about
reloading such dump files, see
Section 7.4.2, “Reloading SQL-Format Backups”
.
By default,
mysqldump
writes information as SQL statements to the standard output. You can save the
output in a file:
shell>
mysqldump [arguments] > file_name
To dump all databases, invoke
mysqldump
with the
--all-databases
[298]
option:
shell>
mysqldump --all-databases > dump.sql
To dump only specific databases, name them on the command line and use the
--databases
[299]
option:
shell>
mysqldump --databases db1 db2 db3 > dump.sql
The
--databases
[299]
option causes all names on the command line to be treated as database
names. Without this option,
mysqldump
treats the first name as a database name and those following
as table names.
With
--all-databases
[298]
or
--databases
[299]
,
mysqldump
writes
CREATE DATABASE
and
USE
statements prior to the dump output for each database. This ensures that when the dump file is
reloaded, it creates each database if it does not exist and makes it the default database so database
contents are loaded into the same database from which they came. If you want to cause the dump
file to force a drop of each database before recreating it, use the
--add-drop-database
[298]
option as well. In this case,
mysqldump
writes a
DROP DATABASE
statement preceding each
CREATE
DATABASE
statement.
To dump a single database, name it on the command line:
shell>
mysqldump --databases test > dump.sql
In the single-database case, it is permissible to omit the
--databases
[299]
option:
shell>
mysqldump test > dump.sql
The difference between the two preceding commands is that without
--databases
[299]
, the dump
output contains no
CREATE DATABASE
or
USE
statements. This has several implications:
• When you reload the dump file, you must specify a default database name so that the server knows
which database to reload.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...