2
.\" Title: \fBmysqldump\fR
3
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
4
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
6
.\" Manual: MySQL Database System
10
.TH "\FBMYSQLDUMP\FR" "1" "04/06/2010" "MySQL 5\&.1" "MySQL Database System"
11
.\" -----------------------------------------------------------------
12
.\" * set default formatting
13
.\" -----------------------------------------------------------------
14
.\" disable hyphenation
16
.\" disable justification (adjust text to left margin only)
18
.\" -----------------------------------------------------------------
19
.\" * MAIN CONTENT STARTS HERE *
20
.\" -----------------------------------------------------------------
22
.\" dumping: databases and tables
23
.\" backups: databases and tables
24
.\" databases: dumping
27
mysqldump \- a database backup program
29
.HP \w'\fBmysqldump\ [\fR\fB\fIoptions\fR\fR\fB]\ [\fR\fB\fIdb_name\fR\fR\fB\ [\fR\fB\fItbl_name\fR\fR\fB\ \&.\&.\&.]]\fR\ 'u
30
\fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] [\fR\fB\fIdb_name\fR\fR\fB [\fR\fB\fItbl_name\fR\fR\fB \&.\&.\&.]]\fR
35
client is a backup program originally written by Igor Romanenko\&. It can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server)\&. The dump typically contains SQL statements to create the table, populate it, or both\&. However,
37
can also be used to generate files in CSV, other delimited text, or XML format\&.
39
If you are doing a backup on the server and your tables all are
41
tables, consider using the
43
instead because it can accomplish faster backups and faster restores\&. See
44
\fBmysqlhotcopy\fR(1)\&.
46
There are three general ways to invoke
53
shell> \fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] \fR\fB\fIdb_name\fR\fR\fB [\fR\fB\fItbl_name\fR\fR\fB \&.\&.\&.]\fR
54
shell> \fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] \-\-databases \fR\fB\fIdb_name\fR\fR\fB \&.\&.\&.\fR
55
shell> \fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] \-\-all\-databases\fR
61
If you do not name any tables following
66
\fB\-\-all\-databases\fR
67
option, entire databases are dumped\&.
72
database by default\&. As of MySQL 5\&.1\&.38,
76
if you name it explicitly on the command line, although currently you must also use the
77
\fB\-\-skip\-lock\-tables\fR
78
option\&. Before 5\&.1\&.38,
82
even if you name it explicitly on the command line\&.
84
To see a list of the options your version of
87
\fBmysqldump \-\-help\fR\&.
91
options are shorthand for groups of other options:
103
is the same as specifying
104
\fB\-\-add\-drop\-table\fR,
105
\fB\-\-add\-locks\fR,
106
\fB\-\-create\-options\fR,
107
\fB\-\-disable\-keys\fR,
108
\fB\-\-extended\-insert\fR,
109
\fB\-\-lock\-tables\fR,
111
\fB\-\-set\-charset\fR\&. All of the options that
113
stands for also are on by default because
128
is the same as specifying
129
\fB\-\-skip\-add\-drop\-table\fR,
130
\fB\-\-skip\-add\-locks\fR,
131
\fB\-\-skip\-comments\fR,
132
\fB\-\-skip\-disable\-keys\fR, and
133
\fB\-\-skip\-set\-charset\fR
137
To reverse the effect of a group option, uses its
138
\fB\-\-skip\-\fR\fB\fIxxx\fR\fR
139
form (\fB\-\-skip\-opt\fR
141
\fB\-\-skip\-compact\fR)\&. It is also possible to select only part of the effect of a group option by following it with options that enable or disable specific features\&. Here are some examples:
151
To select the effect of
153
except for some features, use the
155
option for each feature\&. To disable extended inserts and memory buffering, use
157
\fB\-\-skip\-extended\-insert\fR
158
\fB\-\-skip\-quick\fR\&. (Actually,
159
\fB\-\-skip\-extended\-insert\fR
160
\fB\-\-skip\-quick\fR
161
is sufficient because
176
for all features except index disabling and table locking, use
178
\fB\-\-disable\-keys\fR
179
\fB\-\-lock\-tables\fR\&.
182
When you selectively enable or disable the effect of a group option, order is important because options are processed first to last\&. For example,
183
\fB\-\-disable\-keys\fR
184
\fB\-\-lock\-tables\fR
186
would not have the intended effect; it is the same as
191
can retrieve and dump table contents row by row, or it can retrieve the entire content from a table and buffer it in memory before dumping it\&. Buffering in memory can be a problem if you are dumping large tables\&. To dump tables row by row, use the
194
\fB\-\-opt\fR, which enables
195
\fB\-\-quick\fR)\&. The
198
\fB\-\-quick\fR) is enabled by default, so to enable memory buffering, use
199
\fB\-\-skip\-quick\fR\&.
201
If you are using a recent version of
203
to generate a dump to be reloaded into a very old MySQL server, you should not use the
206
\fB\-\-extended\-insert\fR
215
.nr an-no-space-flag 1
224
from MySQL 5\&.1\&.21 cannot be used to create dumps from MySQL server 5\&.1\&.20 and older\&. This issue is fixed in MySQL 5\&.1\&.22\&. (\m[blue]\fBBug#30123\fR\m[]\&\s-2\u[1]\d\s+2)
229
supports the following options, which can be specified on the command line or in the
233
option file groups\&.
235
also supports the options for processing option files described at
236
Section\ \&4.2.3.3.1, \(lqCommand-Line Options that Affect Option-File Handling\(rq\&.
246
.\" mysqldump: help option
247
.\" help option: mysqldump
251
Display a help message and exit\&.
262
.\" mysqldump: add-drop-database option
263
.\" add-drop-database option: mysqldump
264
\fB\-\-add\-drop\-database\fR
268
statement before each
270
statement\&. This option is typically used in conjunction with the
271
\fB\-\-all\-databases\fR
276
statements are written unless one of those options is specified\&.
287
.\" mysqldump: add-drop-table option
288
.\" add-drop-table option: mysqldump
289
\fB\-\-add\-drop\-table\fR
293
statement before each
306
.\" mysqldump: add-locks option
307
.\" add-locks option: mysqldump
310
Surround each table dump with
314
statements\&. This results in faster inserts when the dump file is reloaded\&. See
315
Section\ \&7.2.21, \(lqSpeed of INSERT Statements\(rq\&.
326
.\" mysqldump: all-databases option
327
.\" all-databases option: mysqldump
328
\fB\-\-all\-databases\fR,
331
Dump all tables in all databases\&. This is the same as using the
333
option and naming all the databases on the command line\&.
344
.\" mysqldump: all-tablespaces option
345
.\" all-tablespaces option: mysqldump
346
\fB\-\-all\-tablespaces\fR,
349
Adds to a table dump all SQL statements needed to create any tablespaces used by an
351
table\&. This information is not otherwise included in the output from
352
\fBmysqldump\fR\&. This option is currently relevant only to MySQL Cluster tables\&.
354
This option was added in MySQL 5\&.1\&.6\&.
365
.\" mysqldump: allow-keywords option
366
.\" allow-keywords option: mysqldump
367
\fB\-\-allow\-keywords\fR
369
Allow creation of column names that are keywords\&. This works by prefixing each column name with the table name\&.
380
.\" mysqldump: character-sets-dir option
381
.\" character-sets-dir option: mysqldump
382
\fB\-\-character\-sets\-dir=\fR\fB\fIpath\fR\fR
384
The directory where character sets are installed\&. See
385
Section\ \&9.5, \(lqCharacter Set Configuration\(rq\&.
396
.\" mysqldump: comments option
397
.\" comments option: mysqldump
401
Write additional information in the dump file such as program version, server version, and host\&. This option is enabled by default\&. To suppress this additional information, use
402
\fB\-\-skip\-comments\fR\&.
413
.\" mysqldump: compact option
414
.\" compact option: mysqldump
417
Produce more compact output\&. This option enables the
418
\fB\-\-skip\-add\-drop\-table\fR,
419
\fB\-\-skip\-add\-locks\fR,
420
\fB\-\-skip\-comments\fR,
421
\fB\-\-skip\-disable\-keys\fR, and
422
\fB\-\-skip\-set\-charset\fR
429
.nr an-no-space-flag 1
436
Prior to MySQL 5\&.1\&.21, this option did not create valid SQL if the database dump contained views\&. The recreation of views requires the creation and removal of temporary tables and this option suppressed the removal of those temporary tables\&. As a workaround, use
439
\fB\-\-add\-drop\-table\fR
440
option and then manually adjust the dump file\&.
453
.\" mysqldump: compatible option
454
.\" compatible option: mysqldump
455
\fB\-\-compatible=\fR\fB\fIname\fR\fR
457
Produce output that is more compatible with other database systems or with older MySQL servers\&. The value of
470
no_field_options\&. To use several values, separate them by commas\&. These values have the same meaning as the corresponding options for setting the server SQL mode\&. See
471
Section\ \&5.1.8, \(lqServer SQL Modes\(rq\&.
473
This option does not guarantee compatibility with other servers\&. It only enables those SQL mode values that are currently available for making dump output more compatible\&. For example,
474
\fB\-\-compatible=oracle\fR
475
does not map data types to Oracle types or use Oracle comment syntax\&.
477
\fIThis option requires a server version of 4\&.1\&.0 or higher\fR\&. With older servers, it does nothing\&.
488
.\" mysqldump: complete-insert option
489
.\" complete-insert option: mysqldump
490
\fB\-\-complete\-insert\fR,
495
statements that include column names\&.
506
.\" mysqldump: compress option
507
.\" compress option: mysqldump
511
Compress all information sent between the client and the server if both support compression\&.
522
.\" mysqldump: create-options option
523
.\" create-options option: mysqldump
524
\fB\-\-create\-options\fR,
527
Include all MySQL\-specific table options in the
540
.\" mysqldump: databases option
541
.\" databases option: mysqldump
545
Dump several databases\&. Normally,
547
treats the first name argument on the command line as a database name and following names as table names\&. With this option, it treats all name arguments as database names\&.
551
statements are included in the output before each new database\&.
562
.\" mysqldump: debug option
563
.\" debug option: mysqldump
564
\fB\-\-debug[=\fR\fB\fIdebug_options\fR\fR\fB]\fR,
565
\fB\-# [\fR\fB\fIdebug_options\fR\fR\fB]\fR
567
Write a debugging log\&. A typical
570
\'d:t:o,\fIfile_name\fR\'\&. The default value is
571
\'d:t:o,/tmp/mysqldump\&.trace\'\&.
582
.\" mysqldump: debug-check option
583
.\" debug-check option: mysqldump
584
\fB\-\-debug\-check\fR
586
Print some debugging information when the program exits\&. This option was added in MySQL 5\&.1\&.21\&.
597
.\" mysqldump: debug-info option
598
.\" debug-info option: mysqldump
599
\fB\-\-debug\-info\fR
601
Print debugging information and memory and CPU usage statistics when the program exits\&. This option was added in MySQL 5\&.1\&.14\&.
612
.\" mysqldump: default-character-set option
613
.\" default-character-set option: mysqldump
614
\fB\-\-default\-character\-set=\fR\fB\fIcharset_name\fR\fR
618
as the default character set\&. See
619
Section\ \&9.5, \(lqCharacter Set Configuration\(rq\&. If no character set is specified,
622
utf8, and earlier versions use
625
Prior to MySQL 5\&.1\&.38, this option has no effect for output data files produced by using the
627
option\&. See the description for that option\&.
638
.\" mysqldump: defaults-extra-file option
639
.\" defaults-extra-file option: mysqldump
640
\fB\-\-defaults\-extra\-file=\fR\fB\fIfilename\fR\fR
642
Set \fB\fIfilename\fR\fR as the file to read default options from after the global defaults files has been read\&.
643
Must be given as first option\&.
654
.\" mysqldump: defaults-file option
655
.\" defaults-file option: mysqldump
656
\fB\-\-defaults\-file=\fR\fB\fIfilename\fR\fR
658
Set \fB\fIfilename\fR\fR as the file to read default options from, override global defaults files\&.
659
Must be given as first option\&.
670
.\" mysqldump: delayed-insert option
671
.\" delayed-insert option: mysqldump
672
\fB\-\-delayed\-insert\fR
676
statements rather than
689
.\" mysqldump: delete-master-logs option
690
.\" delete-master-logs option: mysqldump
691
\fB\-\-delete\-master\-logs\fR
693
On a master replication server, delete the binary logs by sending a
695
statement to the server after performing the dump operation\&. This option automatically enables
696
\fB\-\-master\-data\fR\&.
707
.\" mysqldump: disable-keys option
708
.\" disable-keys option: mysqldump
709
\fB\-\-disable\-keys\fR,
712
For each table, surround the
715
/*!40000 ALTER TABLE \fItbl_name\fR DISABLE KEYS */;
717
/*!40000 ALTER TABLE \fItbl_name\fR ENABLE KEYS */;
718
statements\&. This makes loading the dump file faster because the indexes are created after all rows are inserted\&. This option is effective only for nonunique indexes of
731
.\" mysqldump: dump-date option
732
.\" dump-date option: mysqldump
739
produces a comment at the end of the dump of the following form:
745
\-\- Dump completed on \fIDATE\fR
751
However, the date causes dump files taken at different times to appear to be different, even if the data are otherwise identical\&.
754
\fB\-\-skip\-dump\-date\fR
755
control whether the date is added to the comment\&. The default is
757
(include the date in the comment)\&.
758
\fB\-\-skip\-dump\-date\fR
759
suppresses date printing\&. This option was added in MySQL 5\&.1\&.23\&.
770
.\" mysqldump: events option
771
.\" events option: mysqldump
775
Include Event Scheduler events for the dumped databases in the output\&. This option was added in MySQL 5\&.1\&.8\&.
786
.\" mysqldump: extended-insert option
787
.\" extended-insert option: mysqldump
788
\fB\-\-extended\-insert\fR,
793
syntax that include several
795
lists\&. This results in a smaller dump file and speeds up inserts when the file is reloaded\&.
806
.\" mysqldump: fields-terminated-by option
807
.\" fields-terminated-by option: mysqldump
808
\fB\-\-fields\-terminated\-by=\&.\&.\&.\fR,
809
.\" mysqldump: fields-enclosed-by option
810
.\" fields-enclosed-by option: mysqldump
811
\fB\-\-fields\-enclosed\-by=\&.\&.\&.\fR,
812
.\" mysqldump: fields-optionally-enclosed-by option
813
.\" fields-optionally-enclosed-by option: mysqldump
814
\fB\-\-fields\-optionally\-enclosed\-by=\&.\&.\&.\fR,
815
.\" mysqldump: fields-escaped-by option
816
.\" fields-escaped-by option: mysqldump
817
\fB\-\-fields\-escaped\-by=\&.\&.\&.\fR
819
These options are used with the
821
option and have the same meaning as the corresponding
824
LOAD DATA INFILE\&. See
825
Section\ \&12.2.6, \(lqLOAD DATA INFILE Syntax\(rq\&.
836
.\" mysqldump: first-slave option
837
.\" first-slave option: mysqldump
838
\fB\-\-first\-slave\fR
841
\fB\-\-lock\-all\-tables\fR
843
\fB\-\-first\-slave\fR
844
is removed in MySQL 5\&.5\&.
855
.\" mysqldump: flush-logs option
856
.\" flush-logs option: mysqldump
857
\fB\-\-flush\-logs\fR,
860
Flush the MySQL server log files before starting the dump\&. This option requires the
862
privilege\&. If you use this option in combination with the
863
\fB\-\-all\-databases\fR
864
option, the logs are flushed
865
\fIfor each database dumped\fR\&. The exception is when using
866
\fB\-\-lock\-all\-tables\fR
868
\fB\-\-master\-data\fR: In this case, the logs are flushed only once, corresponding to the moment that all tables are locked\&. If you want your dump and the log flush to happen at exactly the same moment, you should use
869
\fB\-\-flush\-logs\fR
871
\fB\-\-lock\-all\-tables\fR
873
\fB\-\-master\-data\fR\&.
884
.\" mysqldump: flush-privileges option
885
.\" flush-privileges option: mysqldump
886
\fB\-\-flush\-privileges\fR
890
statement to the server after dumping the
892
database\&. This option should be used any time the dump contains the
894
database and any other database that depends on the data in the
896
database for proper restoration\&. This option was added in MySQL 5\&.1\&.12\&.
907
.\" mysqldump: force option
908
.\" force option: mysqldump
912
Continue even if an SQL error occurs during a table dump\&.
914
One use for this option is to cause
916
to continue executing even when it encounters a view that has become invalid because the definition refers to a table that has been dropped\&. Without
919
exits with an error message\&. With
922
prints the error message, but it also writes an SQL comment containing the view definition to the dump output and continues executing\&.
933
.\" mysqldump: host option
934
.\" host option: mysqldump
935
\fB\-\-host=\fR\fB\fIhost_name\fR\fR,
936
\fB\-h \fR\fB\fIhost_name\fR\fR
938
Dump data from the MySQL server on the given host\&. The default host is
950
.\" mysqldump: hex-blob option
951
.\" hex-blob option: mysqldump
954
Dump binary columns using hexadecimal notation (for example,
957
0x616263)\&. The affected data types are
973
.\" mysqldump: ignore-table option
974
.\" ignore-table option: mysqldump
975
\fB\-\-ignore\-table=\fR\fB\fIdb_name\&.tbl_name\fR\fR
977
Do not dump the given table, which must be specified using both the database and table names\&. To ignore multiple tables, use this option multiple times\&. This option also can be used to ignore views\&.
988
.\" mysqldump: insert-ignore option
989
.\" insert-ignore option: mysqldump
990
\fB\-\-insert\-ignore\fR
994
statements rather than
1001
\h'-04'\(bu\h'+03'\c
1007
.\" mysqldump: lines-terminated-by option
1008
.\" lines-terminated-by option: mysqldump
1009
\fB\-\-lines\-terminated\-by=\&.\&.\&.\fR
1011
This option is used with the
1013
option and has the same meaning as the corresponding
1016
LOAD DATA INFILE\&. See
1017
Section\ \&12.2.6, \(lqLOAD DATA INFILE Syntax\(rq\&.
1022
\h'-04'\(bu\h'+03'\c
1028
.\" mysqldump: lock-all-tables option
1029
.\" lock-all-tables option: mysqldump
1030
\fB\-\-lock\-all\-tables\fR,
1033
Lock all tables across all databases\&. This is achieved by acquiring a global read lock for the duration of the whole dump\&. This option automatically turns off
1034
\fB\-\-single\-transaction\fR
1036
\fB\-\-lock\-tables\fR\&.
1041
\h'-04'\(bu\h'+03'\c
1047
.\" mysqldump: lock-tables option
1048
.\" lock-tables option: mysqldump
1049
\fB\-\-lock\-tables\fR,
1052
For each dumped database, lock all tables to be dumped before dumping them\&. The tables are locked with
1054
to allow concurrent inserts in the case of
1056
tables\&. For transactional tables such as
1058
\fB\-\-single\-transaction\fR
1059
is a much better option than
1060
\fB\-\-lock\-tables\fR
1061
because it does not need to lock the tables at all\&.
1064
\fB\-\-lock\-tables\fR
1065
locks tables for each database separately, this option does not guarantee that the tables in the dump file are logically consistent between databases\&. Tables in different databases may be dumped in completely different states\&.
1070
\h'-04'\(bu\h'+03'\c
1076
.\" mysqldump: log-error option
1077
.\" log-error option: mysqldump
1078
\fB\-\-log\-error=\fR\fB\fIfile_name\fR\fR
1080
Log warnings and errors by appending them to the named file\&. The default is to do no logging\&. This option was added in MySQL 5\&.1\&.18\&.
1085
\h'-04'\(bu\h'+03'\c
1091
.\" mysqldump: master-data option
1092
.\" master-data option: mysqldump
1093
\fB\-\-master\-data[=\fR\fB\fIvalue\fR\fR\fB]\fR
1095
Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master\&. It causes the dump output to include a
1097
statement that indicates the binary log coordinates (file name and position) of the dumped server\&. These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave\&.
1099
If the option value is 2, the
1101
statement is written as an SQL comment, and thus is informative only; it has no effect when the dump file is reloaded\&. If the option value is 1, the statement is not written as a comment and takes effect when the dump file is reloaded\&. If no option value is specified, the default value is 1\&.
1103
This option requires the
1105
privilege and the binary log must be enabled\&.
1108
\fB\-\-master\-data\fR
1109
option automatically turns off
1110
\fB\-\-lock\-tables\fR\&. It also turns on
1111
\fB\-\-lock\-all\-tables\fR, unless
1112
\fB\-\-single\-transaction\fR
1113
also is specified, in which case, a global read lock is acquired only for a short time at the beginning of the dump (see the description for
1114
\fB\-\-single\-transaction\fR)\&. In all cases, any action on logs happens at the exact moment of the dump\&.
1116
It is also possible to set up a slave by dumping an existing slave of the master\&. To do this, use the following procedure on the existing slave:
1126
Stop the slave\'s SQL thread and get its current status:
1132
mysql> \fBSTOP SLAVE SQL_THREAD;\fR
1133
mysql> \fBSHOW SLAVE STATUS;\fR
1148
From the output of the
1150
statement, the binary log coordinates of the master server from which the new slave should start replicating are the values of the
1151
Relay_Master_Log_File
1154
fields\&. Denote those values as
1168
Dump the slave server:
1174
shell> \fBmysqldump \-\-master\-data=2 \-\-all\-databases > dumpfile\fR
1195
mysql> \fBSTART SLAVE;\fR
1210
On the new slave, load the dump file:
1216
shell> \fBmysql < dumpfile\fR
1231
On the new slave, set the replication coordinates to those of the master server obtained earlier:
1237
mysql> \fBCHANGE MASTER TO\fR
1238
\-> \fBMASTER_LOG_FILE = \'\fR\fB\fIfile_name\fR\fR\fB\', MASTER_LOG_POS = \fR\fB\fIfile_pos\fR\fR\fB;\fR
1246
statement might also need other parameters, such as
1248
to point the slave to the correct master server host\&. Add any such parameters as necessary\&.
1254
\h'-04'\(bu\h'+03'\c
1260
.\" mysqldump: max-allowed-packet option
1261
.\" max-allowed-packet option: mysqldump
1262
\fB\-\-max\-allowed\-packet=\fR\fB\fIlength\fR\fR
1264
Sets the maximum packet length to send to or recieve from server\&.
1269
\h'-04'\(bu\h'+03'\c
1275
.\" mysqldump: net-buffer-length option
1276
.\" net-buffer-length option: mysqldump
1277
\fB\-\-net\-buffer\-length=\fR\fB\fIlength\fR\fR
1279
Sets the buffer size for TCP/IP and socket communication\&.
1284
\h'-04'\(bu\h'+03'\c
1290
.\" mysqldump: no-autocommit option
1291
.\" no-autocommit option: mysqldump
1292
\fB\-\-no\-autocommit\fR
1296
statements for each dumped table within
1305
\h'-04'\(bu\h'+03'\c
1311
.\" mysqldump: no-create-db option
1312
.\" no-create-db option: mysqldump
1313
\fB\-\-no\-create\-db\fR,
1316
This option suppresses the
1318
statements that are otherwise included in the output if the
1321
\fB\-\-all\-databases\fR
1327
\h'-04'\(bu\h'+03'\c
1333
.\" mysqldump: no-create-info option
1334
.\" no-create-info option: mysqldump
1335
\fB\-\-no\-create\-info\fR,
1340
statements that re\-create each dumped table\&.
1345
\h'-04'\(bu\h'+03'\c
1351
.\" mysqldump: no-data option
1352
.\" no-data option: mysqldump
1356
Do not write any table row information (that is, do not dump table contents)\&. This is useful if you want to dump only the
1358
statement for the table (for example, to create an empty copy of the table by loading the dump file)\&.
1363
\h'-04'\(bu\h'+03'\c
1369
.\" mysqldump: no-defaults option
1370
.\" no-defaults option: mysqldump
1371
\fB\-\-no\-defaults\fR
1373
Do not read default options from any option file\&. This must be given as the first argument\&.
1378
\h'-04'\(bu\h'+03'\c
1384
.\" mysqldump: no-set-names option
1385
.\" no-set-names option: mysqldump
1386
\fB\-\-no\-set\-names\fR,
1389
This has the same effect as
1390
\fB\-\-skip\-set\-charset\fR\&.
1395
\h'-04'\(bu\h'+03'\c
1401
.\" mysqldump: opt option
1402
.\" opt option: mysqldump
1405
This option is shorthand\&. It is the same as specifying
1406
\fB\-\-add\-drop\-table\fR
1407
\fB\-\-add\-locks\fR
1408
\fB\-\-create\-options\fR
1409
\fB\-\-disable\-keys\fR
1410
\fB\-\-extended\-insert\fR
1411
\fB\-\-lock\-tables\fR
1413
\fB\-\-set\-charset\fR\&. It should give you a fast dump operation and produce a dump file that can be reloaded into a MySQL server quickly\&.
1415
\fIThe \fR\fI\fB\-\-opt\fR\fR\fI option is enabled by default\&. Use \fR\fI\fB\-\-skip\-opt\fR\fR\fI to disable it\&.\fR
1416
See the discussion at the beginning of this section for information about selectively enabling or disabling a subset of the options affected by
1422
\h'-04'\(bu\h'+03'\c
1428
.\" mysqldump: order-by-primary option
1429
.\" order-by-primary option: mysqldump
1430
\fB\-\-order\-by\-primary\fR
1432
Dump each table\'s rows sorted by its primary key, or by its first unique index, if such an index exists\&. This is useful when dumping a
1434
table to be loaded into an
1436
table, but will make the dump operation take considerably longer\&.
1441
\h'-04'\(bu\h'+03'\c
1447
.\" mysqldump: password option
1448
.\" password option: mysqldump
1449
\fB\-\-password[=\fR\fB\fIpassword\fR\fR\fB]\fR,
1450
\fB\-p[\fR\fB\fIpassword\fR\fR\fB]\fR
1452
The password to use when connecting to the server\&. If you use the short option form (\fB\-p\fR), you
1454
have a space between the option and the password\&. If you omit the
1460
option on the command line,
1464
Specifying a password on the command line should be considered insecure\&. See
1465
Section\ \&5.3.2.2, \(lqEnd-User Guidelines for Password Security\(rq\&. You can use an option file to avoid giving the password on the command line\&.
1470
\h'-04'\(bu\h'+03'\c
1476
.\" mysqldump: pipe option
1477
.\" pipe option: mysqldump
1481
On Windows, connect to the server via a named pipe\&. This option applies only if the server supports named\-pipe connections\&.
1486
\h'-04'\(bu\h'+03'\c
1492
.\" mysqldump: port option
1493
.\" port option: mysqldump
1494
\fB\-\-port=\fR\fB\fIport_num\fR\fR,
1495
\fB\-P \fR\fB\fIport_num\fR\fR
1497
The TCP/IP port number to use for the connection\&.
1502
\h'-04'\(bu\h'+03'\c
1508
.\" mysqldump: protocol option
1509
.\" protocol option: mysqldump
1510
\fB\-\-protocol={TCP|SOCKET|PIPE|MEMORY}\fR
1512
The connection protocol to use for connecting to the server\&. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want\&. For details on the allowable values, see
1513
Section\ \&4.2.2, \(lqConnecting to the MySQL Server\(rq\&.
1518
\h'-04'\(bu\h'+03'\c
1524
.\" mysqldump: quick option
1525
.\" quick option: mysqldump
1529
This option is useful for dumping large tables\&. It forces
1531
to retrieve rows for a table from the server a row at a time rather than retrieving the entire row set and buffering it in memory before writing it out\&.
1536
\h'-04'\(bu\h'+03'\c
1542
.\" mysqldump: print-defaults option
1543
.\" print-defaults option: mysqldump
1544
\fB\-\-print\-defaults\fR
1546
Print the program argument list and exit\&. This must begiven as the first argument\&.
1551
\h'-04'\(bu\h'+03'\c
1557
.\" mysqldump: quote-names option
1558
.\" quote-names option: mysqldump
1559
\fB\-\-quote\-names\fR,
1562
Quote identifiers (such as database, table, and column names) within
1564
characters\&. If the
1566
SQL mode is enabled, identifiers are quoted within
1568
characters\&. This option is enabled by default\&. It can be disabled with
1569
\fB\-\-skip\-quote\-names\fR, but this option should be given after any option such as
1570
\fB\-\-compatible\fR
1572
\fB\-\-quote\-names\fR\&.
1577
\h'-04'\(bu\h'+03'\c
1583
.\" mysqldump: replace option
1584
.\" replace option: mysqldump
1589
statements rather than
1591
statements\&. This option was added in MySQL 5\&.1\&.3\&.
1596
\h'-04'\(bu\h'+03'\c
1602
.\" mysqldump: result-file option
1603
.\" result-file option: mysqldump
1604
\fB\-\-result\-file=\fR\fB\fIfile_name\fR\fR,
1605
\fB\-r \fR\fB\fIfile_name\fR\fR
1607
Direct output to a given file\&. This option should be used on Windows to prevent newline
1609
characters from being converted to
1611
carriage return/newline sequences\&. The result file is created and its previous contents overwritten, even if an error occurs while generating the dump\&.
1616
\h'-04'\(bu\h'+03'\c
1622
.\" mysqldump: routines option
1623
.\" routines option: mysqldump
1627
Included stored routines (procedures and functions) for the dumped databases in the output\&. Use of this option requires the
1631
table\&. The output generated by using
1637
statements to re\-create the routines\&. However, these statements do not include attributes such as the routine creation and modification timestamps\&. This means that when the routines are reloaded, they will be created with the timestamps equal to the reload time\&.
1639
If you require routines to be re\-created with their original timestamp attributes, do not use
1640
\fB\-\-routines\fR\&. Instead, dump and reload the contents of the
1642
table directly, using a MySQL account that has appropriate privileges for the
1646
This option was added in MySQL 5\&.1\&.2\&. Before that, stored routines are not dumped\&. Routine
1648
values are not dumped until MySQL 5\&.1\&.8\&. This means that before 5\&.1\&.8, when routines are reloaded, they will be created with the definer set to the reloading user\&. If you require routines to be re\-created with their original definer, dump and load the contents of the
1650
table directly as described earlier\&.
1655
\h'-04'\(bu\h'+03'\c
1661
.\" mysqldump: set-charset option
1662
.\" set-charset option: mysqldump
1663
\fB\-\-set\-charset\fR
1666
SET NAMES \fIdefault_character_set\fR
1667
to the output\&. This option is enabled by default\&. To suppress the
1670
\fB\-\-skip\-set\-charset\fR\&.
1675
\h'-04'\(bu\h'+03'\c
1681
.\" mysqldump: single-transaction option
1682
.\" single-transaction option: mysqldump
1683
\fB\-\-single\-transaction\fR
1687
SQL statement to the server before dumping data\&. It is useful only with transactional tables such as
1688
InnoDB, because then it dumps the consistent state of the database at the time when
1690
was issued without blocking any applications\&.
1692
When using this option, you should keep in mind that only
1694
tables are dumped in a consistent state\&. For example, any
1698
tables dumped while using this option may still change state\&.
1701
\fB\-\-single\-transaction\fR
1702
dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection should use the following statements:
1707
TRUNCATE TABLE\&. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the
1709
that is performed by
1711
to retrieve the table contents to obtain incorrect contents or fail\&.
1714
\fB\-\-single\-transaction\fR
1716
\fB\-\-lock\-tables\fR
1717
option are mutually exclusive because
1719
causes any pending transactions to be committed implicitly\&.
1721
This option is not supported for MySQL Cluster tables; the results cannot be guaranteed to be consistent due to the fact that the
1723
storage engine supports only the
1725
transaction isolation level\&. You should always use
1727
backup and restore instead\&.
1729
To dump large tables, you should combine the
1730
\fB\-\-single\-transaction\fR
1737
\h'-04'\(bu\h'+03'\c
1743
.\" mysqldump: skip-comments option
1744
.\" skip-comments option: mysqldump
1745
\fB\-\-skip\-comments\fR
1747
See the description for the
1754
\h'-04'\(bu\h'+03'\c
1760
.\" mysqldump: skip-opt option
1761
.\" skip-opt option: mysqldump
1764
See the description for the
1771
\h'-04'\(bu\h'+03'\c
1777
.\" mysqldump: socket option
1778
.\" socket option: mysqldump
1779
\fB\-\-socket=\fR\fB\fIpath\fR\fR,
1780
\fB\-S \fR\fB\fIpath\fR\fR
1783
localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use\&.
1788
\h'-04'\(bu\h'+03'\c
1794
.\" mysqldump: SSL options
1795
.\" SSL options: mysqldump
1798
Options that begin with
1800
specify whether to connect to the server via SSL and indicate where to find SSL keys and certificates\&. See
1801
Section\ \&5.5.6.3, \(lqSSL Command Options\(rq\&.
1806
\h'-04'\(bu\h'+03'\c
1812
.\" mysqldump: tab option
1813
.\" tab option: mysqldump
1814
\fB\-\-tab=\fR\fB\fIpath\fR\fR,
1815
\fB\-T \fR\fB\fIpath\fR\fR
1817
Produce tab\-separated text\-format data files\&. For each dumped table,
1820
\fItbl_name\fR\&.sql
1821
file that contains the
1823
statement that creates the table, and the server writes a
1824
\fItbl_name\fR\&.txt
1825
file that contains its data\&. The option value is the directory in which to write the files\&.
1831
.nr an-no-space-flag 1
1838
This option should be used only when
1840
is run on the same machine as the
1842
server\&. You must have the
1844
privilege, and the server must have permission to write files in the directory that you specify\&.
1849
data files are formatted using tab characters between column values and a newline at the end of each line\&. The format can be specified explicitly using the
1850
\fB\-\-fields\-\fR\fB\fIxxx\fR\fR
1852
\fB\-\-lines\-terminated\-by\fR
1855
As of MySQL 5\&.1\&.38, column values are converted to the character set specified by the
1856
\fB\-\-default\-character\-set\fR
1857
option\&. Prior to 5\&.1\&.38 or if no such option is present, values are dumped using the
1859
character set\&. In effect, there is no character set conversion\&. If a table contains columns in several character sets, the output data file will as well and you may not be able to reload the file correctly\&.
1864
\h'-04'\(bu\h'+03'\c
1870
.\" mysqldump: tables option
1871
.\" tables option: mysqldump
1880
regards all name arguments following the option as table names\&.
1885
\h'-04'\(bu\h'+03'\c
1891
.\" mysqldump: triggers option
1892
.\" triggers option: mysqldump
1895
Include triggers for each dumped table in the output\&. This option is enabled by default; disable it with
1896
\fB\-\-skip\-triggers\fR\&.
1901
\h'-04'\(bu\h'+03'\c
1907
.\" mysqldump: tz-utc option
1908
.\" tz-utc option: mysqldump
1913
columns to be dumped and reloaded between servers in different time zones\&.
1915
sets its connection time zone to UTC and adds
1916
SET TIME_ZONE=\'+00:00\'
1917
to the dump file\&. Without this option,
1919
columns are dumped and reloaded in the time zones local to the source and destination servers, which can cause the values to change if the servers are in different time zones\&.
1921
also protects against changes due to daylight saving time\&.
1923
is enabled by default\&. To disable it, use
1924
\fB\-\-skip\-tz\-utc\fR\&. This option was added in MySQL 5\&.1\&.2\&.
1929
\h'-04'\(bu\h'+03'\c
1935
.\" mysqldump: user option
1936
.\" user option: mysqldump
1937
\fB\-\-user=\fR\fB\fIuser_name\fR\fR,
1938
\fB\-u \fR\fB\fIuser_name\fR\fR
1940
The MySQL user name to use when connecting to the server\&.
1945
\h'-04'\(bu\h'+03'\c
1951
.\" mysqldump: verbose option
1952
.\" verbose option: mysqldump
1956
Verbose mode\&. Print more information about what the program does\&.
1961
\h'-04'\(bu\h'+03'\c
1967
.\" mysqldump: version option
1968
.\" version option: mysqldump
1972
Display version information and exit\&.
1977
\h'-04'\(bu\h'+03'\c
1983
.\" mysqldump: where option
1984
.\" where option: mysqldump
1985
\fB\-\-where=\'\fR\fB\fIwhere_condition\fR\fR\fB\'\fR,
1986
\fB\-w \'\fR\fB\fIwhere_condition\fR\fR\fB\'\fR
1988
Dump only rows selected by the given
1990
condition\&. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter\&.
1998
\-\-where="user=\'jimf\'"
2009
\h'-04'\(bu\h'+03'\c
2015
.\" mysqldump: xml option
2016
.\" xml option: mysqldump
2020
Write dump output as well\-formed XML\&.
2022
\fBNULL\fR\fB, \fR\fB\'NULL\'\fR\fB, and Empty Values\fR: For a column named
2023
\fIcolumn_name\fR, the
2025
value, an empty string, and the string value
2027
are distinguished from one another in the output generated by this option as follows\&.
2034
\fBXML Representation\fR:
2037
NULL (\fIunknown value\fR)
2039
<field name="\fIcolumn_name\fR" xsi:nil="true" />
2042
\'\' (\fIempty string\fR)
2044
<field name="\fIcolumn_name\fR">\:</field>
2047
\'NULL\' (\fIstring value\fR)
2049
<field name="\fIcolumn_name\fR">\:NULL</field>
2053
Beginning with MySQL 5\&.1\&.12, the output from the
2055
client when run using the
2057
option also follows the preceding rules\&. (See
2058
the section called \(lqMYSQL OPTIONS\(rq\&.)
2060
Beginning with MySQL 5\&.1\&.18, XML output from
2062
includes the XML namespace, as shown here:
2068
shell> \fBmysqldump \-\-xml \-u root world City\fR
2069
<?xml version="1\&.0"?>
2070
<mysqldump xmlns:xsi="http://www\&.w3\&.org/2001/XMLSchema\-instance">
2071
<database name="world">
2072
<table_structure name="City">
2073
<field Field="ID" Type="int(11)" Null="NO" Key="PRI" Extra="auto_increment" />
2074
<field Field="Name" Type="char(35)" Null="NO" Key="" Default="" Extra="" />
2075
<field Field="CountryCode" Type="char(3)" Null="NO" Key="" Default="" Extra="" />
2076
<field Field="District" Type="char(20)" Null="NO" Key="" Default="" Extra="" />
2077
<field Field="Population" Type="int(11)" Null="NO" Key="" Default="0" Extra="" />
2078
<key Table="City" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="ID"
2079
Collation="A" Cardinality="4079" Null="" Index_type="BTREE" Comment="" />
2080
<options Name="City" Engine="MyISAM" Version="10" Row_format="Fixed" Rows="4079"
2081
Avg_row_length="67" Data_length="273293" Max_data_length="18858823439613951"
2082
Index_length="43008" Data_free="0" Auto_increment="4080"
2083
Create_time="2007\-03\-31 01:47:01" Update_time="2007\-03\-31 01:47:02"
2084
Collation="latin1_swedish_ci" Create_options="" Comment="" />
2086
<table_data name="City">
2088
<field name="ID">1</field>
2089
<field name="Name">Kabul</field>
2090
<field name="CountryCode">AFG</field>
2091
<field name="District">Kabol</field>
2092
<field name="Population">1780000</field>
2096
<field name="ID">4079</field>
2097
<field name="Name">Rafah</field>
2098
<field name="CountryCode">PSE</field>
2099
<field name="District">Rafah</field>
2100
<field name="Population">92020</field>
2112
You can also set the following variables by using
2113
\fB\-\-\fR\fB\fIvar_name\fR\fR\fB=\fR\fB\fIvalue\fR\fR
2118
\h'-04'\(bu\h'+03'\c
2126
The maximum size of the buffer for client/server communication\&. The maximum is 1GB\&.
2131
\h'-04'\(bu\h'+03'\c
2139
The initial size of the buffer for client/server communication\&. When creating multiple\-row
2141
statements (as with the
2142
\fB\-\-extended\-insert\fR
2149
length\&. If you increase this variable, you should also ensure that the
2151
variable in the MySQL server is at least this large\&.
2156
is for making a backup of an entire database:
2162
shell> \fBmysqldump \fR\fB\fIdb_name\fR\fR\fB > \fR\fB\fIbackup\-file\&.sql\fR\fR
2168
You can load the dump file back into the server like this:
2174
shell> \fBmysql \fR\fB\fIdb_name\fR\fR\fB < \fR\fB\fIbackup\-file\&.sql\fR\fR
2186
shell> \fBmysql \-e "source \fR\fB\fI/path\-to\-backup/backup\-file\&.sql\fR\fR\fB" \fR\fB\fIdb_name\fR\fR
2193
is also very useful for populating databases by copying data from one MySQL server to another:
2199
shell> \fBmysqldump \-\-opt \fR\fB\fIdb_name\fR\fR\fB | mysql \-\-host=\fR\fB\fIremote_host\fR\fR\fB \-C \fR\fB\fIdb_name\fR\fR
2205
It is possible to dump several databases with one command:
2211
shell> \fBmysqldump \-\-databases \fR\fB\fIdb_name1\fR\fR\fB [\fR\fB\fIdb_name2\fR\fR\fB \&.\&.\&.] > my_databases\&.sql\fR
2217
To dump all databases, use the
2218
\fB\-\-all\-databases\fR
2225
shell> \fBmysqldump \-\-all\-databases > all_databases\&.sql\fR
2235
provides a way of making an online backup:
2241
shell> \fBmysqldump \-\-all\-databases \-\-single\-transaction > all_databases\&.sql\fR
2247
This backup acquires a global read lock on all tables (using
2248
FLUSH TABLES WITH READ LOCK) at the beginning of the dump\&. As soon as this lock has been acquired, the binary log coordinates are read and the lock is released\&. If long updating statements are running when the
2250
statement is issued, the MySQL server may get stalled until those statements finish\&. After that, the dump becomes lock free and does not disturb reads and writes on the tables\&. If the update statements that the MySQL server receives are short (in terms of execution time), the initial lock period should not be noticeable, even with many updates\&.
2252
For point\-in\-time recovery (also known as
2253
\(lqroll\-forward,\(rq
2254
when you need to restore an old backup and replay the changes that happened since that backup), it is often useful to rotate the binary log (see
2255
Section\ \&5.2.4, \(lqThe Binary Log\(rq) or at least know the binary log coordinates to which the dump corresponds:
2261
shell> \fBmysqldump \-\-all\-databases \-\-master\-data=2 > all_databases\&.sql\fR
2273
shell> \fBmysqldump \-\-all\-databases \-\-flush\-logs \-\-master\-data=2\fR
2274
\fB> all_databases\&.sql\fR
2281
\fB\-\-master\-data\fR
2283
\fB\-\-single\-transaction\fR
2284
options can be used simultaneously, which provides a convenient way to make an online backup suitable for use prior to point\-in\-time recovery if tables are stored using the
2288
For more information on making backups, see
2289
Section\ \&6.2, \(lqDatabase Backup Methods\(rq, and
2290
Section\ \&6.3, \(lqExample Backup and Recovery Strategy\(rq\&.
2291
.\" mysqldump: views
2292
.\" mysqldump: problems
2293
.\" mysqldump: workarounds
2295
If you encounter problems backing up views, please read the section that covers restrictions on views which describes a workaround for backing up views when this fails due to insufficient privileges\&. See
2296
Section\ \&D.4, \(lqRestrictions on Views\(rq\&.
2300
Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc.
2302
This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
2304
This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
2306
You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see http://www.gnu.org/licenses/.
2312
\%http://bugs.mysql.com/bug.php?id=30123
2315
For more information, please refer to the MySQL Reference Manual,
2316
which may already be installed locally and which is also available
2317
online at http://dev.mysql.com/doc/.
2319
Sun Microsystems, Inc. (http://www.mysql.com/).