~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to man/mysqldump.1

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.\"     Title: \fBmysqldump\fR
 
2
.\"    Author: 
 
3
.\" Generator: DocBook XSL Stylesheets v1.70.1 <http://docbook.sf.net/>
 
4
.\"      Date: 01/09/2007
 
5
.\"    Manual: MySQL Database System
 
6
.\"    Source: MySQL 5.0
 
7
.\"
 
8
.TH "\fBMYSQLDUMP\fR" "1" "01/09/2007" "MySQL 5.0" "MySQL Database System"
 
9
.\" disable hyphenation
 
10
.nh
 
11
.\" disable justification (adjust text to left margin only)
 
12
.ad l
 
13
.SH "NAME"
 
14
mysqldump \- a database backup program
 
15
.SH "SYNOPSIS"
 
16
.HP 45
 
17
\fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] [\fR\fB\fIdb_name\fR\fR\fB [\fR\fB\fItbl_name\fR\fR\fB ...]]\fR
 
18
.SH "DESCRIPTION"
 
19
.PP
 
20
The
 
21
\fBmysqldump\fR
 
22
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,
 
23
\fBmysqldump\fR
 
24
can also be used to generate files in CSV, other delimited text, or XML format.
 
25
.PP
 
26
If you are doing a backup on the server and your tables all are
 
27
MyISAM
 
28
tables, consider using the
 
29
\fBmysqlhotcopy\fR
 
30
instead because it can accomplish faster backups and faster restores. See
 
31
\fBmysqlhotcopy\fR(1).
 
32
.PP
 
33
There are three general ways to invoke
 
34
\fBmysqldump\fR:
 
35
.sp
 
36
.RS 3n
 
37
.nf
 
38
shell> \fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] \fR\fB\fIdb_name\fR\fR\fB [\fR\fB\fItables\fR\fR\fB]\fR
 
39
shell> \fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] \-\-databases \fR\fB\fIdb_name1\fR\fR\fB [\fR\fB\fIdb_name2\fR\fR\fB \fR\fB\fIdb_name3\fR\fR\fB...]\fR
 
40
shell> \fBmysqldump [\fR\fB\fIoptions\fR\fR\fB] \-\-all\-databases\fR
 
41
.fi
 
42
.RE
 
43
.PP
 
44
If you do not name any tables following
 
45
\fIdb_name\fR
 
46
or if you use the
 
47
\fB\-\-databases\fR
 
48
or
 
49
\fB\-\-all\-databases\fR
 
50
option, entire databases are dumped.
 
51
.PP
 
52
To get a list of the options your version of
 
53
\fBmysqldump\fR
 
54
supports, execute
 
55
\fBmysqldump \-\-help\fR.
 
56
.PP
 
57
Some
 
58
\fBmysqldump\fR
 
59
options are shorthand for groups of other options.
 
60
\fB\-\-opt\fR
 
61
and
 
62
\fB\-\-compact\fR
 
63
fall into this category. For example, use of
 
64
\fB\-\-opt\fR
 
65
is the same as specifying
 
66
\fB\-\-add\-drop\-table \-\-add\-locks \-\-create\-options \-\-disable\-keys \-\-extended\-insert \-\-lock\-tables \-\-quick \-\-set\-charset\fR. Note that all of the options that
 
67
\fB\-\-opt\fR
 
68
stands for also are on by default because
 
69
\fB\-\-opt\fR
 
70
is on by default.
 
71
.PP
 
72
To reverse the effect of a group option, uses its
 
73
\fB\-\-skip\-\fR\fB\fIxxx\fR\fR
 
74
form (\fB\-\-skip\-opt\fR
 
75
or
 
76
\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:
 
77
.TP 3n
 
78
\(bu
 
79
To select the effect of
 
80
\fB\-\-opt\fR
 
81
except for some features, use the
 
82
\fB\-\-skip\fR
 
83
option for each feature. For example, to disable extended inserts and memory buffering, use
 
84
\fB\-\-opt \-\-skip\-extended\-insert \-\-skip\-quick\fR. (As of MySQL 5.0,
 
85
\fB\-\-skip\-extended\-insert \-\-skip\-quick\fR
 
86
is sufficient because
 
87
\fB\-\-opt\fR
 
88
is on by default.)
 
89
.TP 3n
 
90
\(bu
 
91
To reverse
 
92
\fB\-\-opt\fR
 
93
for all features except index disabling and table locking, use
 
94
\fB\-\-skip\-opt \-\-disable\-keys \-\-lock\-tables\fR.
 
95
.sp
 
96
.RE
 
97
.PP
 
98
When you selectively enable or disable the effect of a group option, order is important because options are processed first to last. For example,
 
99
\fB\-\-disable\-keys \-\-lock\-tables \-\-skip\-opt\fR
 
100
would not have the intended effect; it is the same as
 
101
\fB\-\-skip\-opt\fR
 
102
by itself.
 
103
.PP
 
104
\fBmysqldump\fR
 
105
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
 
106
\fB\-\-quick\fR
 
107
option (or
 
108
\fB\-\-opt\fR, which enables
 
109
\fB\-\-quick\fR).
 
110
\fB\-\-opt\fR
 
111
(and hence
 
112
\fB\-\-quick\fR) is enabled by default as of MySQL 5.0 to enable memory buffering, use
 
113
\fB\-\-skip\-quick\fR.
 
114
.PP
 
115
If you are using a recent version of
 
116
\fBmysqldump\fR
 
117
to generate a dump to be reloaded into a very old MySQL server, you should not use the
 
118
\fB\-\-opt\fR
 
119
or
 
120
\fB\-\-extended\-insert\fR
 
121
option. Use
 
122
\fB\-\-skip\-opt\fR
 
123
instead.
 
124
.PP
 
125
\fBmysqldump\fR
 
126
supports the following options:
 
127
.TP 3n
 
128
\(bu
 
129
\fB\-\-help\fR,
 
130
\fB\-?\fR
 
131
.sp
 
132
Display a help message and exit.
 
133
.TP 3n
 
134
\(bu
 
135
\fB\-\-add\-drop\-database\fR
 
136
.sp
 
137
Add a
 
138
DROP DATABASE
 
139
statement before each
 
140
CREATE DATABASE
 
141
statement.
 
142
.TP 3n
 
143
\(bu
 
144
\fB\-\-add\-drop\-table\fR
 
145
.sp
 
146
Add a
 
147
DROP TABLE
 
148
statement before each
 
149
CREATE TABLE
 
150
statement.
 
151
.TP 3n
 
152
\(bu
 
153
\fB\-\-add\-locks\fR
 
154
.sp
 
155
Surround each table dump with
 
156
LOCK TABLES
 
157
and
 
158
UNLOCK TABLES
 
159
statements. This results in faster inserts when the dump file is reloaded. See
 
160
Section\ 2.16, \(lqSpeed of INSERT Statements\(rq.
 
161
.TP 3n
 
162
\(bu
 
163
\fB\-\-all\-databases\fR,
 
164
\fB\-A\fR
 
165
.sp
 
166
Dump all tables in all databases. This is the same as using the
 
167
\fB\-\-databases\fR
 
168
option and naming all the databases on the command line.
 
169
.TP 3n
 
170
\(bu
 
171
\fB\-\-allow\-keywords\fR
 
172
.sp
 
173
Allow creation of column names that are keywords. This works by prefixing each column name with the table name.
 
174
.TP 3n
 
175
\(bu
 
176
\fB\-\-character\-sets\-dir=\fR\fB\fIpath\fR\fR
 
177
.sp
 
178
The directory where character sets are installed. See
 
179
Section\ 9.1, \(lqThe Character Set Used for Data and Sorting\(rq.
 
180
.TP 3n
 
181
\(bu
 
182
\fB\-\-comments\fR,
 
183
\fB\-i\fR
 
184
.sp
 
185
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
 
186
\fB\-\-skip\-comments\fR.
 
187
.TP 3n
 
188
\(bu
 
189
\fB\-\-compact\fR
 
190
.sp
 
191
Produce less verbose output. This option suppresses comments and enables the
 
192
\fB\-\-skip\-add\-drop\-table\fR,
 
193
\fB\-\-no\-set\-names\fR,
 
194
\fB\-\-skip\-disable\-keys\fR, and
 
195
\fB\-\-skip\-add\-locks\fR
 
196
options.
 
197
.TP 3n
 
198
\(bu
 
199
\fB\-\-compatible=\fR\fB\fIname\fR\fR
 
200
.sp
 
201
Produce output that is more compatible with other database systems or with older MySQL servers. The value of
 
202
name
 
203
can be
 
204
ansi,
 
205
mysql323,
 
206
mysql40,
 
207
postgresql,
 
208
oracle,
 
209
mssql,
 
210
db2,
 
211
maxdb,
 
212
no_key_options,
 
213
no_table_options, or
 
214
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
 
215
the section called \(lqSQL MODES\(rq.
 
216
.sp
 
217
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,
 
218
\fB\-\-compatible=oracle\fR
 
219
does not map data types to Oracle types or use Oracle comment syntax.
 
220
.TP 3n
 
221
\(bu
 
222
\fB\-\-complete\-insert\fR,
 
223
\fB\-c\fR
 
224
.sp
 
225
Use complete
 
226
INSERT
 
227
statements that include column names.
 
228
.TP 3n
 
229
\(bu
 
230
\fB\-\-compress\fR,
 
231
\fB\-C\fR
 
232
.sp
 
233
Compress all information sent between the client and the server if both support compression.
 
234
.TP 3n
 
235
\(bu
 
236
\fB\-\-create\-options\fR
 
237
.sp
 
238
Include all MySQL\-specific table options in the
 
239
CREATE TABLE
 
240
statements.
 
241
.TP 3n
 
242
\(bu
 
243
\fB\-\-databases\fR,
 
244
\fB\-B\fR
 
245
.sp
 
246
Dump several databases. Normally,
 
247
\fBmysqldump\fR
 
248
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.
 
249
CREATE DATABASE
 
250
and
 
251
USE
 
252
statements are included in the output before each new database.
 
253
.TP 3n
 
254
\(bu
 
255
\fB\-\-debug[=\fR\fB\fIdebug_options\fR\fR\fB]\fR,
 
256
\fB\-# [\fR\fB\fIdebug_options\fR\fR\fB]\fR
 
257
.sp
 
258
Write a debugging log. The
 
259
\fIdebug_options\fR
 
260
string is often
 
261
\'d:t:o,\fIfile_name\fR'. The default value is
 
262
\'d:t:o,/tmp/mysqldump.trace'.
 
263
.TP 3n
 
264
\(bu
 
265
\fB\-\-default\-character\-set=\fR\fB\fIcharset_name\fR\fR
 
266
.sp
 
267
Use
 
268
\fIcharset_name\fR
 
269
as the default character set. See
 
270
Section\ 9.1, \(lqThe Character Set Used for Data and Sorting\(rq. If no character set is specified,
 
271
\fBmysqldump\fR
 
272
uses
 
273
utf8.
 
274
.TP 3n
 
275
\(bu
 
276
\fB\-\-delayed\-insert\fR
 
277
.sp
 
278
Write
 
279
INSERT DELAYED
 
280
statements rather than
 
281
INSERT
 
282
statements.
 
283
.TP 3n
 
284
\(bu
 
285
\fB\-\-delete\-master\-logs\fR
 
286
.sp
 
287
On a master replication server, delete the binary logs after performing the dump operation. This option automatically enables
 
288
\fB\-\-master\-data\fR.
 
289
.TP 3n
 
290
\(bu
 
291
\fB\-\-disable\-keys\fR,
 
292
\fB\-K\fR
 
293
.sp
 
294
For each table, surround the
 
295
INSERT
 
296
statements with
 
297
/*!40000 ALTER TABLE \fItbl_name\fR DISABLE KEYS */;
 
298
and
 
299
/*!40000 ALTER TABLE \fItbl_name\fR ENABLE KEYS */;
 
300
statements. This makes loading the dump file faster because the indexes are created after all rows are inserted. This option is effective for
 
301
MyISAM
 
302
tables only.
 
303
.TP 3n
 
304
\(bu
 
305
\fB\-\-extended\-insert\fR,
 
306
\fB\-e\fR
 
307
.sp
 
308
Use multiple\-row
 
309
INSERT
 
310
syntax that include several
 
311
VALUES
 
312
lists. This results in a smaller dump file and speeds up inserts when the file is reloaded.
 
313
.TP 3n
 
314
\(bu
 
315
\fB\-\-fields\-terminated\-by=...\fR,
 
316
\fB\-\-fields\-enclosed\-by=...\fR,
 
317
\fB\-\-fields\-optionally\-enclosed\-by=...\fR,
 
318
\fB\-\-fields\-escaped\-by=...\fR
 
319
.sp
 
320
These options are used with the
 
321
\fB\-T\fR
 
322
option and have the same meaning as the corresponding clauses for
 
323
LOAD DATA INFILE. See
 
324
Section\ 2.5, \(lqLOAD DATA INFILE Syntax\(rq.
 
325
.TP 3n
 
326
\(bu
 
327
\fB\-\-first\-slave\fR,
 
328
\fB\-x\fR
 
329
.sp
 
330
Deprecated. Now renamed to
 
331
\fB\-\-lock\-all\-tables\fR.
 
332
.TP 3n
 
333
\(bu
 
334
\fB\-\-flush\-logs\fR,
 
335
\fB\-F\fR
 
336
.sp
 
337
Flush the MySQL server log files before starting the dump. This option requires the
 
338
RELOAD
 
339
privilege. Note that if you use this option in combination with the
 
340
\fB\-\-all\-databases\fR
 
341
(or
 
342
\fB\-A\fR) option, the logs are flushed
 
343
\fIfor each database dumped\fR. The exception is when using
 
344
\fB\-\-lock\-all\-tables\fR
 
345
or
 
346
\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
 
347
\fB\-\-flush\-logs\fR
 
348
together with either
 
349
\fB\-\-lock\-all\-tables\fR
 
350
or
 
351
\fB\-\-master\-data\fR.
 
352
.TP 3n
 
353
\(bu
 
354
\fB\-\-flush\-privileges\fR
 
355
.sp
 
356
Emit a
 
357
FLUSH PRIVILEGES
 
358
statement after dumping the
 
359
mysql
 
360
database. This option should be used any time the dump contains the
 
361
mysql
 
362
database and any other database that depends on the data in the
 
363
mysql
 
364
database for proper restoration. This option was added in MySQL 5.0.26.
 
365
.TP 3n
 
366
\(bu
 
367
\fB\-\-force\fR,
 
368
\fB\-f\fR
 
369
.sp
 
370
Continue even if an SQL error occurs during a table dump.
 
371
.sp
 
372
One use for this option is to cause
 
373
\fBmysqldump\fR
 
374
to continue executing even when it encounters a view that has become invalid because the defintion refers to a table that has been dropped. Without
 
375
\fB\-\-force\fR,
 
376
\fBmysqldump\fR
 
377
exits with an error message. With
 
378
\fB\-\-force\fR,
 
379
\fBmysqldump\fR
 
380
prints the error message, but it also writes a SQL comment containing the view definition to the dump output and continues executing.
 
381
.TP 3n
 
382
\(bu
 
383
\fB\-\-host=\fR\fB\fIhost_name\fR\fR,
 
384
\fB\-h \fR\fB\fIhost_name\fR\fR
 
385
.sp
 
386
Dump data from the MySQL server on the given host. The default host is
 
387
localhost.
 
388
.TP 3n
 
389
\(bu
 
390
\fB\-\-hex\-blob\fR
 
391
.sp
 
392
Dump binary columns using hexadecimal notation (for example,
 
393
\'abc'
 
394
becomes
 
395
0x616263). The affected data types are
 
396
BINARY,
 
397
VARBINARY, and
 
398
BLOB. As of MySQL 5.0.13,
 
399
BIT
 
400
columns are affected as well.
 
401
.TP 3n
 
402
\(bu
 
403
\fB\-\-ignore\-table=\fR\fB\fIdb_name.tbl_name\fR\fR
 
404
.sp
 
405
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.
 
406
.TP 3n
 
407
\(bu
 
408
\fB\-\-insert\-ignore\fR
 
409
.sp
 
410
Write
 
411
INSERT
 
412
statements with the
 
413
IGNORE
 
414
option.
 
415
.TP 3n
 
416
\(bu
 
417
\fB\-\-lines\-terminated\-by=...\fR
 
418
.sp
 
419
This option is used with the
 
420
\fB\-T\fR
 
421
option and has the same meaning as the corresponding clause for
 
422
LOAD DATA INFILE. See
 
423
Section\ 2.5, \(lqLOAD DATA INFILE Syntax\(rq.
 
424
.TP 3n
 
425
\(bu
 
426
\fB\-\-lock\-all\-tables\fR,
 
427
\fB\-x\fR
 
428
.sp
 
429
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
 
430
\fB\-\-single\-transaction\fR
 
431
and
 
432
\fB\-\-lock\-tables\fR.
 
433
.TP 3n
 
434
\(bu
 
435
\fB\-\-lock\-tables\fR,
 
436
\fB\-l\fR
 
437
.sp
 
438
Lock all tables before dumping them. The tables are locked with
 
439
READ LOCAL
 
440
to allow concurrent inserts in the case of
 
441
MyISAM
 
442
tables. For transactional tables such as
 
443
InnoDB
 
444
and
 
445
BDB,
 
446
\fB\-\-single\-transaction\fR
 
447
is a much better option, because it does not need to lock the tables at all.
 
448
.sp
 
449
Please note that when dumping multiple databases,
 
450
\fB\-\-lock\-tables\fR
 
451
locks tables for each database separately. Therefore, 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.
 
452
.TP 3n
 
453
\(bu
 
454
\fB\-\-master\-data[=\fR\fB\fIvalue\fR\fR\fB]\fR
 
455
.sp
 
456
Write the binary log filename and position to the output. This option requires the
 
457
RELOAD
 
458
privilege and the binary log must be enabled. If the option value is equal to 1, the position and filename are written to the dump output in the form of a
 
459
CHANGE MASTER
 
460
statement. If the dump is from a master server and you use it to set up a slave server, the
 
461
CHANGE MASTER
 
462
statement causes the slave to start from the correct position in the master's binary logs. If the option value is equal to 2, the
 
463
CHANGE MASTER
 
464
statement is written as an SQL comment. (This is the default action if
 
465
\fIvalue\fR
 
466
is omitted.)
 
467
.sp
 
468
The
 
469
\fB\-\-master\-data\fR
 
470
option automatically turns off
 
471
\fB\-\-lock\-tables\fR. It also turns on
 
472
\fB\-\-lock\-all\-tables\fR, unless
 
473
\fB\-\-single\-transaction\fR
 
474
also is specified (in which case, a global read lock is acquired only for a short time at the beginning of the dump. See also the description for
 
475
\fB\-\-single\-transaction\fR. In all cases, any action on logs happens at the exact moment of the dump.
 
476
.TP 3n
 
477
\(bu
 
478
\fB\-\-no\-autocommit\fR
 
479
.sp
 
480
Enclose the
 
481
INSERT
 
482
statements for each dumped table within
 
483
SET AUTOCOMMIT=0
 
484
and
 
485
COMMIT
 
486
statements.
 
487
.TP 3n
 
488
\(bu
 
489
\fB\-\-no\-create\-db\fR,
 
490
\fB\-n\fR
 
491
.sp
 
492
This option suppresses the
 
493
CREATE DATABASE
 
494
statements that are otherwise included in the output if the
 
495
\fB\-\-databases\fR
 
496
or
 
497
\fB\-\-all\-databases\fR
 
498
option is given.
 
499
.TP 3n
 
500
\(bu
 
501
\fB\-\-no\-create\-info\fR,
 
502
\fB\-t\fR
 
503
.sp
 
504
Do not write
 
505
CREATE TABLE
 
506
statements that re\-create each dumped table.
 
507
.TP 3n
 
508
\(bu
 
509
\fB\-\-no\-data\fR,
 
510
\fB\-d\fR
 
511
.sp
 
512
Do not write any table row information (that is, do not dump table contents). This is very useful if you want to dump only the
 
513
CREATE TABLE
 
514
statement for the table.
 
515
.TP 3n
 
516
\(bu
 
517
\fB\-\-opt\fR
 
518
.sp
 
519
This option is shorthand; it is the same as specifying
 
520
\fB\-\-add\-drop\-table \-\-add\-locks \-\-create\-options \-\-disable\-keys \-\-extended\-insert \-\-lock\-tables \-\-quick \-\-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.
 
521
.sp
 
522
\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
 
523
See the discussion at the beginning of this section for information about selectively enabling or disabling certain of the options affected by
 
524
\fB\-\-opt\fR.
 
525
.TP 3n
 
526
\(bu
 
527
\fB\-\-order\-by\-primary\fR
 
528
.sp
 
529
Sorts each table's rows by its primary key, or by its first unique index, if such an index exists. This is useful when dumping a
 
530
MyISAM
 
531
table to be loaded into an
 
532
InnoDB
 
533
table, but will make the dump itself take considerably longer.
 
534
.TP 3n
 
535
\(bu
 
536
\fB\-\-password[=\fR\fB\fIpassword\fR\fR\fB]\fR,
 
537
\fB\-p[\fR\fB\fIpassword\fR\fR\fB]\fR
 
538
.sp
 
539
The password to use when connecting to the server. If you use the short option form (\fB\-p\fR), you
 
540
\fIcannot\fR
 
541
have a space between the option and the password. If you omit the
 
542
\fIpassword\fR
 
543
value following the
 
544
\fB\-\-password\fR
 
545
or
 
546
\fB\-p\fR
 
547
option on the command line, you are prompted for one.
 
548
.sp
 
549
Specifying a password on the command line should be considered insecure. See
 
550
Section\ 7.6, \(lqKeeping Your Password Secure\(rq.
 
551
.TP 3n
 
552
\(bu
 
553
\fB\-\-port=\fR\fB\fIport_num\fR\fR,
 
554
\fB\-P \fR\fB\fIport_num\fR\fR
 
555
.sp
 
556
The TCP/IP port number to use for the connection.
 
557
.TP 3n
 
558
\(bu
 
559
\fB\-\-protocol={TCP|SOCKET|PIPE|MEMORY}\fR
 
560
.sp
 
561
The connection protocol to use.
 
562
.TP 3n
 
563
\(bu
 
564
\fB\-\-quick\fR,
 
565
\fB\-q\fR
 
566
.sp
 
567
This option is useful for dumping large tables. It forces
 
568
\fBmysqldump\fR
 
569
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.
 
570
.TP 3n
 
571
\(bu
 
572
\fB\-\-quote\-names\fR,
 
573
\fB\-Q\fR
 
574
.sp
 
575
Quote database, table, and column names within \(oq`\(cq characters. If the
 
576
ANSI_QUOTES
 
577
SQL mode is enabled, names are quoted within \(oq"\(cq characters. This option is enabled by default. It can be disabled with
 
578
\fB\-\-skip\-quote\-names\fR, but this option should be given after any option such as
 
579
\fB\-\-compatible\fR
 
580
that may enable
 
581
\fB\-\-quote\-names\fR.
 
582
.TP 3n
 
583
\(bu
 
584
\fB\-\-result\-file=\fR\fB\fIfile\fR\fR,
 
585
\fB\-r \fR\fB\fIfile\fR\fR
 
586
.sp
 
587
Direct output to a given file. This option should be used on Windows to prevent newline \(oq\\n\(cq characters from being converted to \(oq\\r\\n\(cq carriage return/newline sequences. The result file is created and its contents overwritten, even if an error occurs while generating the dump. The previous contents are lost.
 
588
.TP 3n
 
589
\(bu
 
590
\fB\-\-routines\fR,
 
591
\fB\-R\fR
 
592
.sp
 
593
Dump stored routines (functions and procedures) from the dumped databases. Use of this option requires the
 
594
SELECT
 
595
privilege for the
 
596
mysql.proc
 
597
table. The output generated by using
 
598
\fB\-\-routines\fR
 
599
contains
 
600
CREATE PROCEDURE
 
601
and
 
602
CREATE FUNCTION
 
603
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.
 
604
.sp
 
605
If you require routines to be re\-created with their original timestamp attributes, do not use
 
606
\fB\-\-routines\fR. Instead, dump and reload the contents of the
 
607
mysql.proc
 
608
table directly, using a MySQL account that has appropriate privileges for the
 
609
mysql
 
610
database.
 
611
.sp
 
612
This option was added in MySQL 5.0.13. Before that, stored routines are not dumped. Routine
 
613
DEFINER
 
614
values are not dumped until MySQL 5.0.20. This means that before 5.0.20, 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
 
615
mysql.proc
 
616
table directly as described earlier.
 
617
.TP 3n
 
618
\(bu
 
619
\fB\-\-set\-charset\fR
 
620
.sp
 
621
Add
 
622
SET NAMES \fIdefault_character_set\fR
 
623
to the output. This option is enabled by default. To suppress the
 
624
SET NAMES
 
625
statement, use
 
626
\fB\-\-skip\-set\-charset\fR.
 
627
.TP 3n
 
628
\(bu
 
629
\fB\-\-single\-transaction\fR
 
630
.sp
 
631
This option issues a
 
632
BEGIN
 
633
SQL statement before dumping data from the server. It is useful only with transactional tables such as
 
634
InnoDB
 
635
and
 
636
BDB, because then it dumps the consistent state of the database at the time when
 
637
BEGIN
 
638
was issued without blocking any applications.
 
639
.sp
 
640
When using this option, you should keep in mind that only
 
641
InnoDB
 
642
tables are dumped in a consistent state. For example, any
 
643
MyISAM
 
644
or
 
645
MEMORY
 
646
tables dumped while using this option may still change state.
 
647
.sp
 
648
The
 
649
\fB\-\-single\-transaction\fR
 
650
option and the
 
651
\fB\-\-lock\-tables\fR
 
652
option are mutually exclusive, because
 
653
LOCK TABLES
 
654
causes any pending transactions to be committed implicitly.
 
655
.sp
 
656
This option is not supported for MySQL Cluster tables; the results cannot be guaranteed to be consistent due to the fact that the
 
657
NDBCluster
 
658
storage engine supports only the
 
659
READ_COMMITTED
 
660
transaction isolation level. You should always use
 
661
NDB
 
662
backup and restore instead.
 
663
.sp
 
664
To dump large tables, you should combine this option with
 
665
\fB\-\-quick\fR.
 
666
.TP 3n
 
667
\(bu
 
668
\fB\-\-skip\-opt\fR
 
669
.sp
 
670
See the description for the
 
671
\fB\-\-opt\fR
 
672
option.
 
673
.TP 3n
 
674
\(bu
 
675
\fB\-\-socket=\fR\fB\fIpath\fR\fR,
 
676
\fB\-S \fR\fB\fIpath\fR\fR
 
677
.sp
 
678
For connections to
 
679
localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.
 
680
.TP 3n
 
681
\(bu
 
682
\fB\-\-skip\-comments\fR
 
683
.sp
 
684
See the description for the
 
685
\fB\-\-comments\fR
 
686
option.
 
687
.TP 3n
 
688
\(bu
 
689
\fB\-\-ssl*\fR
 
690
.sp
 
691
Options that begin with
 
692
\fB\-\-ssl\fR
 
693
specify whether to connect to the server via SSL and indicate where to find SSL keys and certificates. See
 
694
Section\ 7.7.3, \(lqSSL Command Options\(rq.
 
695
.TP 3n
 
696
\(bu
 
697
\fB\-\-tab=\fR\fB\fIpath\fR\fR,
 
698
\fB\-T \fR\fB\fIpath\fR\fR
 
699
.sp
 
700
Produce tab\-separated data files. For each dumped table,
 
701
\fBmysqldump\fR
 
702
creates a
 
703
\fI\fItbl_name\fR\fR\fI.sql\fR
 
704
file that contains the
 
705
CREATE TABLE
 
706
statement that creates the table, and a
 
707
\fI\fItbl_name\fR\fR\fI.txt\fR
 
708
file that contains its data. The option value is the directory in which to write the files.
 
709
.sp
 
710
By default, the
 
711
\fI.txt\fR
 
712
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
 
713
\fB\-\-fields\-\fR\fB\fIxxx\fR\fR
 
714
and
 
715
\fB\-\-lines\-terminated\-by\fR
 
716
options.
 
717
.sp
 
718
\fBNote\fR: This option should be used only when
 
719
\fBmysqldump\fR
 
720
is run on the same machine as the
 
721
\fBmysqld\fR
 
722
server. You must have the
 
723
FILE
 
724
privilege, and the server must have permission to write files in the directory that you specify.
 
725
.TP 3n
 
726
\(bu
 
727
\fB\-\-tables\fR
 
728
.sp
 
729
Override the
 
730
\fB\-\-databases\fR
 
731
or
 
732
\fB\-B\fR
 
733
option.
 
734
\fBmysqldump\fR
 
735
regards all name arguments following the option as table names.
 
736
.TP 3n
 
737
\(bu
 
738
\fB\-\-triggers\fR
 
739
.sp
 
740
Dump triggers for each dumped table. This option is enabled by default; disable it with
 
741
\fB\-\-skip\-triggers\fR. This option was added in MySQL 5.0.11. Before that, triggers are not dumped.
 
742
.TP 3n
 
743
\(bu
 
744
\fB\-\-tz\-utc\fR
 
745
.sp
 
746
Add
 
747
SET TIME_ZONE='+00:00'
 
748
to the dump file so that
 
749
TIMESTAMP
 
750
columns can be dumped and reloaded between servers in different time zones. Without this option,
 
751
TIMESTAMP
 
752
columns are dumped and reloaded in the time zones local to the source and destination servers, which can cause the values to change.
 
753
\fB\-\-tz\-utc\fR
 
754
also protects against changes due to daylight saving time.
 
755
\fB\-\-tz\-utc\fR
 
756
is enabled by default. To disable it, use
 
757
\fB\-\-skip\-tz\-utc\fR. This option was added in MySQL 5.0.15.
 
758
.TP 3n
 
759
\(bu
 
760
\fB\-\-user=\fR\fB\fIuser_name\fR\fR,
 
761
\fB\-u \fR\fB\fIuser_name\fR\fR
 
762
.sp
 
763
The MySQL username to use when connecting to the server.
 
764
.TP 3n
 
765
\(bu
 
766
\fB\-\-verbose\fR,
 
767
\fB\-v\fR
 
768
.sp
 
769
Verbose mode. Print more information about what the program does.
 
770
.TP 3n
 
771
\(bu
 
772
\fB\-\-version\fR,
 
773
\fB\-V\fR
 
774
.sp
 
775
Display version information and exit.
 
776
.TP 3n
 
777
\(bu
 
778
\fB\-\-where='\fR\fB\fIwhere_condition\fR\fR\fB'\fR,
 
779
\fB\-w '\fR\fB\fIwhere_condition\fR\fR\fB'\fR
 
780
.sp
 
781
Dump only rows selected by the given
 
782
WHERE
 
783
condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.
 
784
.sp
 
785
Examples:
 
786
.sp
 
787
.RS 3n
 
788
.nf
 
789
\-\-where="user='jimf'"
 
790
\-w"userid>1"
 
791
\-w"userid<1"
 
792
.fi
 
793
.RE
 
794
.TP 3n
 
795
\(bu
 
796
\fB\-\-xml\fR,
 
797
\fB\-X\fR
 
798
.sp
 
799
Write dump output as well\-formed XML.
 
800
.sp
 
801
\fBNULL\fR\fB, \fR\fB'NULL'\fR\fB, and Empty Values\fR: For some column named
 
802
\fIcolumn_name\fR, the
 
803
NULL
 
804
value, an empty string, and the string value
 
805
\'NULL'
 
806
are distinguished from one another in the output generated by this option as follows:
 
807
.TS
 
808
allbox tab(:);
 
809
l l
 
810
l l
 
811
l l
 
812
l l.
 
813
T{
 
814
\fBValue\fR:
 
815
T}:T{
 
816
\fBXML Representation\fR:
 
817
T}
 
818
T{
 
819
NULL (\fIunknown value\fR)
 
820
T}:T{
 
821
<field name="\fIcolumn_name\fR"
 
822
                      xsi:nil="true" />
 
823
T}
 
824
T{
 
825
\'' (\fIempty string\fR)
 
826
T}:T{
 
827
<field
 
828
                      name="\fIcolumn_name\fR"></field>
 
829
T}
 
830
T{
 
831
\'NULL' (\fIstring value\fR)
 
832
T}:T{
 
833
<field
 
834
                      name="\fIcolumn_name\fR">NULL</field>
 
835
T}
 
836
.TE
 
837
.sp
 
838
Beginning with MySQL 5.0.26, the output from the
 
839
\fBmysql\fR
 
840
client when run using the
 
841
\fB\-\-xml\fR
 
842
option also follows these rules. (See
 
843
the section called \(lq\fBMYSQL\fR OPTIONS\(rq.)
 
844
.sp
 
845
.RE
 
846
.PP
 
847
You can also set the following variables by using
 
848
\fB\-\-\fR\fB\fIvar_name\fR\fR\fB=\fR\fB\fIvalue\fR\fR
 
849
syntax:
 
850
.TP 3n
 
851
\(bu
 
852
max_allowed_packet
 
853
.sp
 
854
The maximum size of the buffer for client/server communication. The maximum is 1GB.
 
855
.TP 3n
 
856
\(bu
 
857
net_buffer_length
 
858
.sp
 
859
The initial size of the buffer for client/server communication. When creating multiple\-row\-insert statements (as with option
 
860
\fB\-\-extended\-insert\fR
 
861
or
 
862
\fB\-\-opt\fR),
 
863
\fBmysqldump\fR
 
864
creates rows up to
 
865
net_buffer_length
 
866
length. If you increase this variable, you should also ensure that the
 
867
net_buffer_length
 
868
variable in the MySQL server is at least this large.
 
869
.sp
 
870
.RE
 
871
.PP
 
872
It is also possible to set variables by using
 
873
\fB\-\-set\-variable=\fR\fB\fIvar_name\fR\fR\fB=\fR\fB\fIvalue\fR\fR
 
874
or
 
875
\fB\-O \fR\fB\fIvar_name\fR\fR\fB=\fR\fB\fIvalue\fR\fR
 
876
syntax.
 
877
\fIThis syntax is deprecated\fR.
 
878
.PP
 
879
The most common use of
 
880
\fBmysqldump\fR
 
881
is probably for making a backup of an entire database:
 
882
.sp
 
883
.RS 3n
 
884
.nf
 
885
shell> \fBmysqldump \fR\fB\fIdb_name\fR\fR\fB > \fR\fB\fIbackup\-file.sql\fR\fR
 
886
.fi
 
887
.RE
 
888
.PP
 
889
You can read the dump file back into the server like this:
 
890
.sp
 
891
.RS 3n
 
892
.nf
 
893
shell> \fBmysql \fR\fB\fIdb_name\fR\fR\fB < \fR\fB\fIbackup\-file.sql\fR\fR
 
894
.fi
 
895
.RE
 
896
.PP
 
897
Or like this:
 
898
.sp
 
899
.RS 3n
 
900
.nf
 
901
shell> \fBmysql \-e "source \fR\fB\fI/path\-to\-backup/backup\-file.sql\fR\fR\fB" \fR\fB\fIdb_name\fR\fR
 
902
.fi
 
903
.RE
 
904
.PP
 
905
\fBmysqldump\fR
 
906
is also very useful for populating databases by copying data from one MySQL server to another:
 
907
.sp
 
908
.RS 3n
 
909
.nf
 
910
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
 
911
.fi
 
912
.RE
 
913
.PP
 
914
It is possible to dump several databases with one command:
 
915
.sp
 
916
.RS 3n
 
917
.nf
 
918
shell> \fBmysqldump \-\-databases \fR\fB\fIdb_name1\fR\fR\fB [\fR\fB\fIdb_name2\fR\fR\fB ...] > my_databases.sql\fR
 
919
.fi
 
920
.RE
 
921
.PP
 
922
To dump all databases, use the
 
923
\fB\-\-all\-databases\fR
 
924
option:
 
925
.sp
 
926
.RS 3n
 
927
.nf
 
928
shell> \fBmysqldump \-\-all\-databases > all_databases.sql\fR
 
929
.fi
 
930
.RE
 
931
.PP
 
932
For
 
933
InnoDB
 
934
tables,
 
935
mysqldump
 
936
provides a way of making an online backup:
 
937
.sp
 
938
.RS 3n
 
939
.nf
 
940
shell> \fBmysqldump \-\-all\-databases \-\-single\-transaction > all_databases.sql\fR
 
941
.fi
 
942
.RE
 
943
.PP
 
944
This backup just needs to acquire a global read lock on all tables (using
 
945
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 and only if one long updating statement is running when the
 
946
FLUSH
 
947
statement is issued, the MySQL server may get stalled until that long statement finishes, and then the dump becomes lock\-free. 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.
 
948
.PP
 
949
For point\-in\-time recovery (also known as
 
950
\(lqroll\-forward,\(rq
 
951
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
 
952
Section\ 10.3, \(lqThe Binary Log\(rq) or at least know the binary log coordinates to which the dump corresponds:
 
953
.sp
 
954
.RS 3n
 
955
.nf
 
956
shell> \fBmysqldump \-\-all\-databases \-\-master\-data=2 > all_databases.sql\fR
 
957
.fi
 
958
.RE
 
959
.PP
 
960
Or:
 
961
.sp
 
962
.RS 3n
 
963
.nf
 
964
shell> \fBmysqldump \-\-all\-databases \-\-flush\-logs \-\-master\-data=2\fR
 
965
              \fB> all_databases.sql\fR
 
966
.fi
 
967
.RE
 
968
.PP
 
969
The
 
970
\fB\-\-master\-data\fR
 
971
and
 
972
\fB\-\-single\-transaction\fR
 
973
options can be used simultaneously, which provides a convenient way to make an online backup suitable for point\-in\-time recovery if tables are stored using the
 
974
InnoDB
 
975
storage engine.
 
976
.PP
 
977
For more information on making backups, see
 
978
Section\ 8.1, \(lqDatabase Backups\(rq, and
 
979
Section\ 8.2, \(lqExample Backup and Recovery Strategy\(rq.
 
980
.PP
 
981
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
 
982
Section\ 4, \(lqRestrictions on Views\(rq.
 
983
.SH "COPYRIGHT"
 
984
.PP
 
985
Copyright 1997\-2006 MySQL AB
 
986
.PP
 
987
This documentation is NOT distributed under a GPL license. Use of this documentation is subject to the following terms: You may create a printed copy of this documentation solely for your own personal use. Conversion to other formats is allowed as long as the actual content is not altered or edited in any way. You shall not publish or distribute this documentation in any form or on any media, except if you distribute the documentation in a manner similar to how MySQL disseminates it (that is, electronically for download on a Web site with the software) or on a CD\-ROM or similar medium, provided however that the documentation is disseminated together with the software on the same medium. Any other use, such as any dissemination of printed copies or use of this documentation, in whole or in part, in another publication, requires the prior written consent from an authorized representative of MySQL AB. MySQL AB reserves any and all rights to this documentation not expressly granted above.
 
988
.PP
 
989
Please email
 
990
<docs@mysql.com>
 
991
for more information.
 
992
.SH "SEE ALSO"
 
993
msql2mysql(1),
 
994
my_print_defaults(1),
 
995
myisam_ftdump(1),
 
996
myisamchk(1),
 
997
myisamlog(1),
 
998
myisampack(1),
 
999
mysql(1),
 
1000
mysql.server(1),
 
1001
mysql_config(1),
 
1002
mysql_explain_log(1),
 
1003
mysql_fix_privilege_tables(1),
 
1004
mysql_tzinfo_to_sql(1),
 
1005
mysql_upgrade(1),
 
1006
mysql_zap(1),
 
1007
mysqlaccess(1),
 
1008
mysqladmin(1),
 
1009
mysqlbinlog(1),
 
1010
mysqlcheck(1),
 
1011
mysqld(8),
 
1012
mysqld_multi(1),
 
1013
mysqld_safe(1),
 
1014
mysqlhotcopy(1),
 
1015
mysqlimport(1),
 
1016
mysqlmanager(8),
 
1017
mysqlshow(1),
 
1018
perror(1),
 
1019
replace(1),
 
1020
safe_mysqld(1)
 
1021
.P
 
1022
For more information, please refer to the MySQL Reference Manual,
 
1023
which may already be installed locally and which is also available
 
1024
online at http://dev.mysql.com/doc/.
 
1025
.SH AUTHOR
 
1026
MySQL AB (http://www.mysql.com/).
 
1027
This software comes with no warranty.