1MYSQLDUMP(1) MySQL Database System MYSQLDUMP(1)
2
3
4
6 mysqldump - a database backup program
7
9 mysqldump [options] [db_name [tbl_name ...]]
10
12 The mysqldump client utility performs logical backups, producing a set
13 of SQL statements that can be executed to reproduce the original
14 database object definitions and table data. It dumps one or more MySQL
15 databases for backup or transfer to another SQL server. The mysqldump
16 command can also generate output in CSV, other delimited text, or XML
17 format.
18
19 Tip
20 Consider using the MySQL Shell dump utilities[1], which provide
21 parallel dumping with multiple threads, file compression, and
22 progress information display, as well as cloud features such as
23 Oracle Cloud Infrastructure Object Storage streaming, and MySQL
24 Database Service compatibility checks and modifications. Dumps can
25 be easily imported into a MySQL Server instance or a MySQL Database
26 Service DB System using the MySQL Shell load dump utilities[2].
27 Installation instructions for MySQL Shell can be found here[3].
28
29 • Performance and Scalability Considerations
30
31 • Invocation Syntax
32
33 • Option Syntax - Alphabetical Summary
34
35 • Connection Options
36
37 • Option-File Options
38
39 • DDL Options
40
41 • Debug Options
42
43 • Help Options
44
45 • Internationalization Options
46
47 • Replication Options
48
49 • Format Options
50
51 • Filtering Options
52
53 • Performance Options
54
55 • Transactional Options
56
57 • Option Groups
58
59 • Examples
60
61 • Restrictions
62
63 mysqldump requires at least the SELECT privilege for dumped tables,
64 SHOW VIEW for dumped views, TRIGGER for dumped triggers, LOCK TABLES if
65 the --single-transaction option is not used, and (as of MySQL 8.0.21)
66 PROCESS if the --no-tablespaces option is not used. Certain options
67 might require other privileges as noted in the option descriptions.
68
69 To reload a dump file, you must have the privileges required to execute
70 the statements that it contains, such as the appropriate CREATE
71 privileges for objects created by those statements.
72
73 mysqldump output can include ALTER DATABASE statements that change the
74 database collation. These may be used when dumping stored programs to
75 preserve their character encodings. To reload a dump file containing
76 such statements, the ALTER privilege for the affected database is
77 required.
78
79 Note
80 A dump made using PowerShell on Windows with output redirection
81 creates a file that has UTF-16 encoding:
82
83 mysqldump [options] > dump.sql
84
85 However, UTF-16 is not permitted as a connection character set (see
86 the section called “Impermissible Client Character Sets”), so the
87 dump file cannot be loaded correctly. To work around this issue,
88 use the --result-file option, which creates the output in ASCII
89 format:
90
91 mysqldump [options] --result-file=dump.sql
92 Performance and Scalability Considerations
93
94 mysqldump advantages include the convenience and flexibility of viewing
95 or even editing the output before restoring. You can clone databases
96 for development and DBA work, or produce slight variations of an
97 existing database for testing. It is not intended as a fast or scalable
98 solution for backing up substantial amounts of data. With large data
99 sizes, even if the backup step takes a reasonable time, restoring the
100 data can be very slow because replaying the SQL statements involves
101 disk I/O for insertion, index creation, and so on.
102
103 For large-scale backup and restore, a physical backup is more
104 appropriate, to copy the data files in their original format that can
105 be restored quickly:
106
107 • If your tables are primarily InnoDB tables, or if you have a mix of
108 InnoDB and MyISAM tables, consider using the mysqlbackup command of
109 the MySQL Enterprise Backup product. (Available as part of the
110 Enterprise subscription.) It provides the best performance for
111 InnoDB backups with minimal disruption; it can also back up tables
112 from MyISAM and other storage engines; and it provides a number of
113 convenient options to accommodate different backup scenarios. See
114 Section 30.2, “MySQL Enterprise Backup Overview”.
115
116 mysqldump can retrieve and dump table contents row by row, or it can
117 retrieve the entire content from a table and buffer it in memory before
118 dumping it. Buffering in memory can be a problem if you are dumping
119 large tables. To dump tables row by row, use the --quick option (or
120 --opt, which enables --quick). The --opt option (and hence --quick) is
121 enabled by default, so to enable memory buffering, use --skip-quick.
122
123 If you are using a recent version of mysqldump to generate a dump to be
124 reloaded into a very old MySQL server, use the --skip-opt option
125 instead of the --opt or --extended-insert option.
126
127 For additional information about mysqldump, see Section 7.4, “Using
128 mysqldump for Backups”. Invocation Syntax
129
130 There are in general three ways to use mysqldump—in order to dump a set
131 of one or more tables, a set of one or more complete databases, or an
132 entire MySQL server—as shown here:
133
134 mysqldump [options] db_name [tbl_name ...]
135 mysqldump [options] --databases db_name ...
136 mysqldump [options] --all-databases
137
138 To dump entire databases, do not name any tables following db_name, or
139 use the --databases or --all-databases option.
140
141 To see a list of the options your version of mysqldump supports, issue
142 the command mysqldump --help. Option Syntax - Alphabetical Summary
143
144 mysqldump supports the following options, which can be specified on the
145 command line or in the [mysqldump] and [client] groups of an option
146 file. For information about option files used by MySQL programs, see
147 Section 4.2.2.2, “Using Option Files”. Connection Options
148
149 The mysqldump command logs into a MySQL server to extract information.
150 The following options specify how to connect to the MySQL server,
151 either on the same machine or a remote system.
152
153 • --bind-address=ip_address On a computer having multiple network
154 interfaces, use this option to select which interface to use for
155 connecting to the MySQL server.
156
157 • --compress, -C Compress all information sent between the client and
158 the server if possible. See Section 4.2.8, “Connection Compression
159 Control”.
160
161 As of MySQL 8.0.18, this option is deprecated. Expect it to be
162 removed in a future version of MySQL. See the section called
163 “Configuring Legacy Connection Compression”.
164
165 • --compression-algorithms=value The permitted compression algorithms
166 for connections to the server. The available algorithms are the
167 same as for the protocol_compression_algorithms system variable.
168 The default value is uncompressed.
169
170 For more information, see Section 4.2.8, “Connection Compression
171 Control”.
172
173 This option was added in MySQL 8.0.18.
174
175 • --default-auth=plugin A hint about which client-side authentication
176 plugin to use. See Section 6.2.17, “Pluggable Authentication”.
177
178 • --enable-cleartext-plugin Enable the mysql_clear_password cleartext
179 authentication plugin. (See Section 6.4.1.4, “Client-Side Cleartext
180 Pluggable Authentication”.)
181
182 • --get-server-public-key Request from the server the public key
183 required for RSA key pair-based password exchange. This option
184 applies to clients that authenticate with the caching_sha2_password
185 authentication plugin. For that plugin, the server does not send
186 the public key unless requested. This option is ignored for
187 accounts that do not authenticate with that plugin. It is also
188 ignored if RSA-based password exchange is not used, as is the case
189 when the client connects to the server using a secure connection.
190
191 If --server-public-key-path=file_name is given and specifies a
192 valid public key file, it takes precedence over
193 --get-server-public-key.
194
195 For information about the caching_sha2_password plugin, see
196 Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
197
198 • --host=host_name, -h host_name Dump data from the MySQL server on
199 the given host. The default host is localhost.
200
201 • --login-path=name Read options from the named login path in the
202 .mylogin.cnf login path file. A “login path” is an option group
203 containing options that specify which MySQL server to connect to
204 and which account to authenticate as. To create or modify a login
205 path file, use the mysql_config_editor utility. See
206 mysql_config_editor(1).
207
208 For additional information about this and other option-file
209 options, see Section 4.2.2.3, “Command-Line Options that Affect
210 Option-File Handling”.
211
212 • --password[=password], -p[password] The password of the MySQL
213 account used for connecting to the server. The password value is
214 optional. If not given, mysqldump prompts for one. If given, there
215 must be no space between --password= or -p and the password
216 following it. If no password option is specified, the default is to
217 send no password.
218
219 Specifying a password on the command line should be considered
220 insecure. To avoid giving the password on the command line, use an
221 option file. See Section 6.1.2.1, “End-User Guidelines for Password
222 Security”.
223
224 To explicitly specify that there is no password and that mysqldump
225 should not prompt for one, use the --skip-password option.
226
227 • --pipe, -W On Windows, connect to the server using a named pipe.
228 This option applies only if the server was started with the
229 named_pipe system variable enabled to support named-pipe
230 connections. In addition, the user making the connection must be a
231 member of the Windows group specified by the
232 named_pipe_full_access_group system variable.
233
234 • --plugin-dir=dir_name The directory in which to look for plugins.
235 Specify this option if the --default-auth option is used to specify
236 an authentication plugin but mysqldump does not find it. See
237 Section 6.2.17, “Pluggable Authentication”.
238
239 • --port=port_num, -P port_num For TCP/IP connections, the port
240 number to use.
241
242 • --protocol={TCP|SOCKET|PIPE|MEMORY} The transport protocol to use
243 for connecting to the server. It is useful when the other
244 connection parameters normally result in use of a protocol other
245 than the one you want. For details on the permissible values, see
246 Section 4.2.7, “Connection Transport Protocols”.
247
248 • --server-public-key-path=file_name The path name to a file in PEM
249 format containing a client-side copy of the public key required by
250 the server for RSA key pair-based password exchange. This option
251 applies to clients that authenticate with the sha256_password or
252 caching_sha2_password authentication plugin. This option is ignored
253 for accounts that do not authenticate with one of those plugins. It
254 is also ignored if RSA-based password exchange is not used, as is
255 the case when the client connects to the server using a secure
256 connection.
257
258 If --server-public-key-path=file_name is given and specifies a
259 valid public key file, it takes precedence over
260 --get-server-public-key.
261
262 For sha256_password, this option applies only if MySQL was built
263 using OpenSSL.
264
265 For information about the sha256_password and caching_sha2_password
266 plugins, see Section 6.4.1.3, “SHA-256 Pluggable Authentication”,
267 and Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
268
269 • --socket=path, -S path For connections to localhost, the Unix
270 socket file to use, or, on Windows, the name of the named pipe to
271 use.
272
273 On Windows, this option applies only if the server was started with
274 the named_pipe system variable enabled to support named-pipe
275 connections. In addition, the user making the connection must be a
276 member of the Windows group specified by the
277 named_pipe_full_access_group system variable.
278
279 • --ssl* Options that begin with --ssl specify whether to connect to
280 the server using encryption and indicate where to find SSL keys and
281 certificates. See the section called “Command Options for Encrypted
282 Connections”.
283
284 • --ssl-fips-mode={OFF|ON|STRICT} Controls whether to enable FIPS
285 mode on the client side. The --ssl-fips-mode option differs from
286 other --ssl-xxx options in that it is not used to establish
287 encrypted connections, but rather to affect which cryptographic
288 operations to permit. See Section 6.8, “FIPS Support”.
289
290 These --ssl-fips-mode values are permitted:
291
292 • OFF: Disable FIPS mode.
293
294 • ON: Enable FIPS mode.
295
296 • STRICT: Enable “strict” FIPS mode.
297
298
299 Note
300 If the OpenSSL FIPS Object Module is not available, the only
301 permitted value for --ssl-fips-mode is OFF. In this case,
302 setting --ssl-fips-mode to ON or STRICT causes the client to
303 produce a warning at startup and to operate in non-FIPS mode.
304
305 • --tls-ciphersuites=ciphersuite_list The permissible ciphersuites
306 for encrypted connections that use TLSv1.3. The value is a list of
307 one or more colon-separated ciphersuite names. The ciphersuites
308 that can be named for this option depend on the SSL library used to
309 compile MySQL. For details, see Section 6.3.2, “Encrypted
310 Connection TLS Protocols and Ciphers”.
311
312 This option was added in MySQL 8.0.16.
313
314 • --tls-version=protocol_list The permissible TLS protocols for
315 encrypted connections. The value is a list of one or more
316 comma-separated protocol names. The protocols that can be named for
317 this option depend on the SSL library used to compile MySQL. For
318 details, see Section 6.3.2, “Encrypted Connection TLS Protocols and
319 Ciphers”.
320
321 • --user=user_name, -u user_name The user name of the MySQL account
322 to use for connecting to the server.
323
324 • --zstd-compression-level=level The compression level to use for
325 connections to the server that use the zstd compression algorithm.
326 The permitted levels are from 1 to 22, with larger values
327 indicating increasing levels of compression. The default zstd
328 compression level is 3. The compression level setting has no effect
329 on connections that do not use zstd compression.
330
331 For more information, see Section 4.2.8, “Connection Compression
332 Control”.
333
334 This option was added in MySQL 8.0.18.
335 Option-File Options
336
337 These options are used to control which option files to read.
338
339 • --defaults-extra-file=file_name Read this option file after the
340 global option file but (on Unix) before the user option file. If
341 the file does not exist or is otherwise inaccessible, an error
342 occurs. If file_name is not an absolute path name, it is
343 interpreted relative to the current directory.
344
345 For additional information about this and other option-file
346 options, see Section 4.2.2.3, “Command-Line Options that Affect
347 Option-File Handling”.
348
349 • --defaults-file=file_name Use only the given option file. If the
350 file does not exist or is otherwise inaccessible, an error occurs.
351 If file_name is not an absolute path name, it is interpreted
352 relative to the current directory.
353
354 Exception: Even with --defaults-file, client programs read
355 .mylogin.cnf.
356
357 For additional information about this and other option-file
358 options, see Section 4.2.2.3, “Command-Line Options that Affect
359 Option-File Handling”.
360
361 • --defaults-group-suffix=str Read not only the usual option groups,
362 but also groups with the usual names and a suffix of str. For
363 example, mysqldump normally reads the [client] and [mysqldump]
364 groups. If this option is given as --defaults-group-suffix=_other,
365 mysqldump also reads the [client_other] and [mysqldump_other]
366 groups.
367
368 For additional information about this and other option-file
369 options, see Section 4.2.2.3, “Command-Line Options that Affect
370 Option-File Handling”.
371
372 • --no-defaults Do not read any option files. If program startup
373 fails due to reading unknown options from an option file,
374 --no-defaults can be used to prevent them from being read.
375
376 The exception is that the .mylogin.cnf file is read in all cases,
377 if it exists. This permits passwords to be specified in a safer way
378 than on the command line even when --no-defaults is used. To create
379 .mylogin.cnf, use the mysql_config_editor utility. See
380 mysql_config_editor(1).
381
382 For additional information about this and other option-file
383 options, see Section 4.2.2.3, “Command-Line Options that Affect
384 Option-File Handling”.
385
386 • --print-defaults Print the program name and all options that it
387 gets from option files.
388
389 For additional information about this and other option-file
390 options, see Section 4.2.2.3, “Command-Line Options that Affect
391 Option-File Handling”.
392 DDL Options
393
394 Usage scenarios for mysqldump include setting up an entire new MySQL
395 instance (including database tables), and replacing data inside an
396 existing instance with existing databases and tables. The following
397 options let you specify which things to tear down and set up when
398 restoring a dump, by encoding various DDL statements within the dump
399 file.
400
401 • --add-drop-database Write a DROP DATABASE statement before each
402 CREATE DATABASE statement. This option is typically used in
403 conjunction with the --all-databases or --databases option because
404 no CREATE DATABASE statements are written unless one of those
405 options is specified.
406
407 Note
408 In MySQL 8.0, the mysql schema is considered a system schema
409 that cannot be dropped by end users. If --add-drop-database is
410 used with --all-databases or with --databases where the list of
411 schemas to be dumped includes mysql, the dump file contains a
412 DROP DATABASE `mysql` statement that causes an error when the
413 dump file is reloaded.
414
415 Instead, to use --add-drop-database, use --databases with a
416 list of schemas to be dumped, where the list does not include
417 mysql.
418
419 • --add-drop-table Write a DROP TABLE statement before each CREATE
420 TABLE statement.
421
422 • --add-drop-trigger Write a DROP TRIGGER statement before each
423 CREATE TRIGGER statement.
424
425 • --all-tablespaces, -Y Adds to a table dump all SQL statements
426 needed to create any tablespaces used by an NDB table. This
427 information is not otherwise included in the output from mysqldump.
428 This option is currently relevant only to NDB Cluster tables.
429
430 • --no-create-db, -n Suppress the CREATE DATABASE statements that are
431 otherwise included in the output if the --databases or
432 --all-databases option is given.
433
434 • --no-create-info, -t Do not write CREATE TABLE statements that
435 create each dumped table.
436
437 Note
438 This option does not exclude statements creating log file
439 groups or tablespaces from mysqldump output; however, you can
440 use the --no-tablespaces option for this purpose.
441
442 • --no-tablespaces, -y This option suppresses all CREATE LOGFILE
443 GROUP and CREATE TABLESPACE statements in the output of mysqldump.
444
445 • --replace Write REPLACE statements rather than INSERT statements.
446 Debug Options
447
448 The following options print debugging information, encode debugging
449 information in the dump file, or let the dump operation proceed
450 regardless of potential problems.
451
452 • --allow-keywords Permit creation of column names that are keywords.
453 This works by prefixing each column name with the table name.
454
455 • --comments, -i Write additional information in the dump file such
456 as program version, server version, and host. This option is
457 enabled by default. To suppress this additional information, use
458 --skip-comments.
459
460 • --debug[=debug_options], -# [debug_options] Write a debugging log.
461 A typical debug_options string is d:t:o,file_name. The default
462 value is d:t:o,/tmp/mysqldump.trace.
463
464 This option is available only if MySQL was built using WITH_DEBUG.
465 MySQL release binaries provided by Oracle are not built using this
466 option.
467
468 • --debug-check Print some debugging information when the program
469 exits.
470
471 This option is available only if MySQL was built using WITH_DEBUG.
472 MySQL release binaries provided by Oracle are not built using this
473 option.
474
475 • --debug-info Print debugging information and memory and CPU usage
476 statistics when the program exits.
477
478 This option is available only if MySQL was built using WITH_DEBUG.
479 MySQL release binaries provided by Oracle are not built using this
480 option.
481
482 • --dump-date If the --comments option is given, mysqldump produces a
483 comment at the end of the dump of the following form:
484
485 -- Dump completed on DATE
486
487 However, the date causes dump files taken at different times to
488 appear to be different, even if the data are otherwise identical.
489 --dump-date and --skip-dump-date control whether the date is added
490 to the comment. The default is --dump-date (include the date in the
491 comment). --skip-dump-date suppresses date printing.
492
493 • --force, -f Ignore all errors; continue even if an SQL error occurs
494 during a table dump.
495
496 One use for this option is to cause mysqldump to continue executing
497 even when it encounters a view that has become invalid because the
498 definition refers to a table that has been dropped. Without
499 --force, mysqldump exits with an error message. With --force,
500 mysqldump prints the error message, but it also writes an SQL
501 comment containing the view definition to the dump output and
502 continues executing.
503
504 If the --ignore-error option is also given to ignore specific
505 errors, --force takes precedence.
506
507 • --log-error=file_name Log warnings and errors by appending them to
508 the named file. The default is to do no logging.
509
510 • --skip-comments See the description for the --comments option.
511
512 • --verbose, -v Verbose mode. Print more information about what the
513 program does.
514 Help Options
515
516 The following options display information about the mysqldump command
517 itself.
518
519 • --help, -? Display a help message and exit.
520
521 • --version, -V Display version information and exit.
522 Internationalization Options
523
524 The following options change how the mysqldump command represents
525 character data with national language settings.
526
527 • --character-sets-dir=dir_name The directory where character sets
528 are installed. See Section 10.15, “Character Set Configuration”.
529
530 • --default-character-set=charset_name Use charset_name as the
531 default character set. See Section 10.15, “Character Set
532 Configuration”. If no character set is specified, mysqldump uses
533 utf8.
534
535 • --no-set-names, -N Turns off the --set-charset setting, the same as
536 specifying --skip-set-charset.
537
538 • --set-charset Write SET NAMES default_character_set to the output.
539 This option is enabled by default. To suppress the SET NAMES
540 statement, use --skip-set-charset.
541 Replication Options
542
543 The mysqldump command is frequently used to create an empty instance,
544 or an instance including data, on a replica server in a replication
545 configuration. The following options apply to dumping and restoring
546 data on replication source servers and replicas.
547
548 • --apply-slave-statements For a replica dump produced with the
549 --dump-slave option, add a STOP REPLICA | SLAVE statement before
550 the statement with the binary log coordinates, and a START REPLICA
551 | SLAVE statement at the end of the output.
552
553 • --delete-master-logs On a replication source server, delete the
554 binary logs by sending a PURGE BINARY LOGS statement to the server
555 after performing the dump operation. This option requires the
556 RELOAD privilege as well as privileges sufficient to execute that
557 statement. This option automatically enables --master-data.
558
559 • --dump-slave[=value] This option is similar to --master-data except
560 that it is used to dump a replica server to produce a dump file
561 that can be used to set up another server as a replica that has the
562 same source as the dumped server. It causes the dump output to
563 include a CHANGE REPLICATION SOURCE TO statement (from MySQL
564 8.0.23) or CHANGE MASTER TO statement (before MySQL 8.0.23) that
565 indicates the binary log coordinates (file name and position) of
566 the dumped replica's source. The CHANGE REPLICATION SOURCE TO
567 statement reads the values of Relay_Master_Log_File and
568 Exec_Master_Log_Pos from the SHOW REPLICA | SLAVE STATUS output and
569 uses them for SOURCE_LOG_FILE and SOURCE_LOG_POS respectively.
570 These are the replication source server coordinates from which the
571 replica starts replicating.
572
573 Note
574 Inconsistencies in the sequence of transactions from the relay
575 log which have been executed can cause the wrong position to be
576 used. See Section 17.5.1.34, “Replication and Transaction
577 Inconsistencies” for more information.
578 --dump-slave causes the coordinates from the source to be used
579 rather than those of the dumped server, as is done by the
580 --master-data option. In addition, specifiying this option causes
581 the --master-data option to be overridden, if used, and effectively
582 ignored.
583
584 Warning
585 This option should not be used if the server where the dump is
586 going to be applied uses gtid_mode=ON and
587 MASTER_AUTOPOSITION=1.
588 The option value is handled the same way as for --master-data.
589 Setting no value or 1 causes a CHANGE REPLICATION SOURCE TO
590 statement (from MySQL 8.0.23) or CHANGE MASTER TO statement (before
591 MySQL 8.0.23) to be written to the dump. Setting 2 causes the
592 statement to be written but encased in SQL comments. It has the
593 same effect as --master-data in terms of enabling or disabling
594 other options and in how locking is handled.
595
596 This option causes mysqldump to stop the replication SQL thread
597 before the dump and restart it again after.
598
599 --dump-slave sends a SHOW REPLICA | SLAVE STATUS statement to the
600 server to obtain information, so it requires privileges sufficient
601 to execute that statement.
602
603 In conjunction with --dump-slave, the --apply-slave-statements and
604 --include-master-host-port options can also be used.
605
606 • --include-master-host-port For the CHANGE REPLICATION SOURCE TO
607 statement (from MySQL 8.0.23) or CHANGE MASTER TO statement (before
608 MySQL 8.0.23) in a replica dump produced with the --dump-slave
609 option, add SOURCE_HOST | MASTER_HOST and SOURCE_PORT | MASTER_PORT
610 options for the host name and TCP/IP port number of the replica's
611 source.
612
613 • --master-data[=value] Use this option to dump a replication source
614 server to produce a dump file that can be used to set up another
615 server as a replica of the source. It causes the dump output to
616 include a CHANGE REPLICATION SOURCE TO statement (from MySQL
617 8.0.23) or CHANGE MASTER TO statement (before MySQL 8.0.23) that
618 indicates the binary log coordinates (file name and position) of
619 the dumped server. These are the replication source server
620 coordinates from which the replica should start replicating after
621 you load the dump file into the replica.
622
623 If the option value is 2, the CHANGE REPLICATION SOURCE TO | CHANGE
624 MASTER TO statement is written as an SQL comment, and thus is
625 informative only; it has no effect when the dump file is reloaded.
626 If the option value is 1, the statement is not written as a comment
627 and takes effect when the dump file is reloaded. If no option value
628 is specified, the default value is 1.
629
630 --master-data sends a SHOW MASTER STATUS statement to the server to
631 obtain information, so it requires privileges sufficient to execute
632 that statement. This option also requires the RELOAD privilege and
633 the binary log must be enabled.
634
635 The --master-data option automatically turns off --lock-tables. It
636 also turns on --lock-all-tables, unless --single-transaction also
637 is specified, in which case, a global read lock is acquired only
638 for a short time at the beginning of the dump (see the description
639 for --single-transaction). In all cases, any action on logs happens
640 at the exact moment of the dump.
641
642 It is also possible to set up a replica by dumping an existing
643 replica of the source, using the --dump-slave option, which
644 overrides --master-data and causes it to be ignored if both options
645 are used.
646
647 • --set-gtid-purged=value This option is for servers that use
648 GTID-based replication (gtid_mode=ON). It controls the inclusion of
649 a SET @@GLOBAL.gtid_purged statement in the dump output, which
650 updates the value of gtid_purged on a server where the dump file is
651 reloaded, to add the GTID set from the source server's
652 gtid_executed system variable. gtid_purged holds the GTIDs of all
653 transactions that have been applied on the server, but do not exist
654 on any binary log file on the server. mysqldump therefore adds the
655 GTIDs for the transactions that were executed on the source server,
656 so that the target server records these transactions as applied,
657 although it does not have them in its binary logs.
658 --set-gtid-purged also controls the inclusion of a SET
659 @@SESSION.sql_log_bin=0 statement, which disables binary logging
660 while the dump file is being reloaded. This statement prevents new
661 GTIDs from being generated and assigned to the transactions in the
662 dump file as they are executed, so that the original GTIDs for the
663 transactions are used.
664
665 If you do not set the --set-gtid-purged option, the default is that
666 a SET @@GLOBAL.gtid_purged statement is included in the dump output
667 if GTIDs are enabled on the server you are backing up, and the set
668 of GTIDs in the global value of the gtid_executed system variable
669 is not empty. A SET @@SESSION.sql_log_bin=0 statement is also
670 included if GTIDs are enabled on the server.
671
672 In MySQL 5.6 and 5.7, you can replace the value of gtid_purged with
673 a specified GTID set, provided that gtid_executed and gtid_purged
674 are empty. From MySQL 8.0, you can either replace the value of
675 gtid_purged with a specified GTID set, or you can add a plus sign
676 (+) to the statement to append a specified GTID set to the GTID set
677 that is already held by gtid_purged. mysqldump's SET
678 @@GLOBAL.gtid_purged statement includes a plus sign (+) in a
679 version comment that takes effect when the dump file is replayed on
680 releases from MySQL 8.0, meaning that for these releases, the GTID
681 set from the dump file is added to the existing gtid_purged value.
682 For MySQL 5.6 and 5.7, the value of gtid_purged is replaced with
683 the GTID set from the dump file, which can only happen when
684 gtid_executed is the empty set (so when replication has not been
685 started previously, or when replication was not previously using
686 GTIDs). For the exact details of how the SET @@GLOBAL.gtid_purged
687 statement operates, see the gtid_purged description for the release
688 where the dump file is to be replayed.
689
690 It is important to note that the value that is included by
691 mysqldump for the SET @@GLOBAL.gtid_purged statement includes the
692 GTIDs of all transactions in the gtid_executed set on the server,
693 even those that changed suppressed parts of the database, or other
694 databases on the server that were not included in a partial dump.
695 This can mean that after the gtid_purged value has been updated on
696 the server where the dump file is replayed, GTIDs are present that
697 do not relate to any data on the target server. If you do not
698 replay any further dump files on the target server, the extraneous
699 GTIDs do not cause any problems with the future operation of the
700 server, but they make it harder to compare or reconcile GTID sets
701 on different servers in the replication topology. If you do replay
702 a further dump file on the target server that contains the same
703 GTIDs (for example, another partial dump from the same origin
704 server), any SET @@GLOBAL.gtid_purged statement in the second dump
705 file fails. In this case, either remove the statement manually
706 before replaying the dump file, or output the dump file without the
707 statement.
708
709 Note
710 For MySQL 5.6 and 5.7, it is not recommended to load a dump
711 file when GTIDs are enabled on the server (gtid_mode=ON), if
712 your dump file includes system tables. mysqldump issues DML
713 instructions for the system tables which use the
714 non-transactional MyISAM storage engine, and this combination
715 is not permitted when GTIDs are enabled.
716 If the SET @@GLOBAL.gtid_purged statement would not have the
717 desired result on your target server, you can exclude the statement
718 from the output, or (from MySQL 8.0.17) include it but comment it
719 out so that it is not actioned automatically. You can also include
720 the statement but manually edit it in the dump file to achieve the
721 desired result.
722
723 The possible values for the --set-gtid-purged option are as
724 follows:
725
726 AUTO
727 The default value. If GTIDs are enabled on the server you are
728 backing up and gtid_executed is not empty, SET
729 @@GLOBAL.gtid_purged is added to the output, containing the
730 GTID set from gtid_executed. If GTIDs are enabled, SET
731 @@SESSION.sql_log_bin=0 is added to the output. If GTIDs are
732 not enabled on the server, the statements are not added to the
733 output.
734
735 OFF
736 SET @@GLOBAL.gtid_purged is not added to the output, and SET
737 @@SESSION.sql_log_bin=0 is not added to the output. For a
738 server where GTIDs are not in use, use this option or AUTO.
739 Only use this option for a server where GTIDs are in use if you
740 are sure that the required GTID set is already present in
741 gtid_purged on the target server and should not be changed, or
742 if you plan to identify and add any missing GTIDs manually.
743
744 ON
745 If GTIDs are enabled on the server you are backing up, SET
746 @@GLOBAL.gtid_purged is added to the output (unless
747 gtid_executed is empty), and SET @@SESSION.sql_log_bin=0 is
748 added to the output. An error occurs if you set this option but
749 GTIDs are not enabled on the server. For a server where GTIDs
750 are in use, use this option or AUTO, unless you are sure that
751 the GTIDs in gtid_executed are not needed on the target server.
752
753 COMMENTED
754 Available from MySQL 8.0.17. If GTIDs are enabled on the server
755 you are backing up, SET @@GLOBAL.gtid_purged is added to the
756 output (unless gtid_executed is empty), but it is commented
757 out. This means that the value of gtid_executed is available in
758 the output, but no action is taken automatically when the dump
759 file is reloaded. SET @@SESSION.sql_log_bin=0 is added to the
760 output, and it is not commented out. With COMMENTED, you can
761 control the use of the gtid_executed set manually or through
762 automation. For example, you might prefer to do this if you are
763 migrating data to another server that already has different
764 active databases.
765 Format Options
766
767 The following options specify how to represent the entire dump file or
768 certain kinds of data in the dump file. They also control whether
769 certain optional information is written to the dump file.
770
771 • --compact Produce more compact output. This option enables the
772 --skip-add-drop-table, --skip-add-locks, --skip-comments,
773 --skip-disable-keys, and --skip-set-charset options.
774
775 • --compatible=name Produce output that is more compatible with other
776 database systems or with older MySQL servers. The only permitted
777 value for this option is ansi, which has the same meaning as the
778 corresponding option for setting the server SQL mode. See
779 Section 5.1.11, “Server SQL Modes”.
780
781 • --complete-insert, -c Use complete INSERT statements that include
782 column names.
783
784 • --create-options Include all MySQL-specific table options in the
785 CREATE TABLE statements.
786
787 • --fields-terminated-by=..., --fields-enclosed-by=...,
788 --fields-optionally-enclosed-by=..., --fields-escaped-by=... These
789 options are used with the --tab option and have the same meaning as
790 the corresponding FIELDS clauses for LOAD DATA. See Section 13.2.7,
791 “LOAD DATA Statement”.
792
793 • --hex-blob Dump binary columns using hexadecimal notation (for
794 example, 'abc' becomes 0x616263). The affected data types are
795 BINARY, VARBINARY, BLOB types, BIT, all spatial data types, and
796 other non-binary data types when used with the binary character
797 set.
798
799 • --lines-terminated-by=... This option is used with the --tab
800 option and has the same meaning as the corresponding LINES clause
801 for LOAD DATA. See Section 13.2.7, “LOAD DATA Statement”.
802
803 • --quote-names, -Q Quote identifiers (such as database, table, and
804 column names) within ` characters. If the ANSI_QUOTES SQL mode is
805 enabled, identifiers are quoted within " characters. This option is
806 enabled by default. It can be disabled with --skip-quote-names, but
807 this option should be given after any option such as --compatible
808 that may enable --quote-names.
809
810 • --result-file=file_name, -r file_name Direct output to the named
811 file. The result file is created and its previous contents
812 overwritten, even if an error occurs while generating the dump.
813
814 This option should be used on Windows to prevent newline \n
815 characters from being converted to \r\n carriage return/newline
816 sequences.
817
818 • --show-create-skip-secondary-engine=value Excludes the SECONDARY
819 ENGINE clause from CREATE TABLE statements. It does so by enabling
820 the show_create_table_skip_secondary_engine system variable for the
821 duration of the dump operation. Alternatively, you can enable the
822 show_create_table_skip_secondary_engine system variable prior to
823 using mysqldump.
824
825 This option was added in MySQL 8.0.18. Attempting a mysqldump
826 operation with the --show-create-skip-secondary-engine option on a
827 release prior to MySQL 8.0.18 that does not support the
828 show_create_table_skip_secondary_engine variable causes an error.
829
830 • --tab=dir_name, -T dir_name Produce tab-separated text-format data
831 files. For each dumped table, mysqldump creates a tbl_name.sql file
832 that contains the CREATE TABLE statement that creates the table,
833 and the server writes a tbl_name.txt file that contains its data.
834 The option value is the directory in which to write the files.
835
836 Note
837 This option should be used only when mysqldump is run on the
838 same machine as the mysqld server. Because the server creates
839 *.txt files in the directory that you specify, the directory
840 must be writable by the server and the MySQL account that you
841 use must have the FILE privilege. Because mysqldump creates
842 *.sql in the same directory, it must be writable by your system
843 login account.
844 By default, the .txt data files are formatted using tab characters
845 between column values and a newline at the end of each line. The
846 format can be specified explicitly using the --fields-xxx and
847 --lines-terminated-by options.
848
849 Column values are converted to the character set specified by the
850 --default-character-set option.
851
852 • --tz-utc This option enables TIMESTAMP columns to be dumped and
853 reloaded between servers in different time zones. mysqldump sets
854 its connection time zone to UTC and adds SET TIME_ZONE='+00:00' to
855 the dump file. Without this option, TIMESTAMP columns are dumped
856 and reloaded in the time zones local to the source and destination
857 servers, which can cause the values to change if the servers are in
858 different time zones. --tz-utc also protects against changes due
859 to daylight saving time. --tz-utc is enabled by default. To
860 disable it, use --skip-tz-utc.
861
862 • --xml, -X Write dump output as well-formed XML.
863
864 NULL, 'NULL', and Empty Values: For a column named column_name, the
865 NULL value, an empty string, and the string value 'NULL' are
866 distinguished from one another in the output generated by this
867 option as follows.
868
869 ┌─────────────────────┬────────────────────────────────────────────┐
870 │Value: │ XML Representation: │
871 ├─────────────────────┼────────────────────────────────────────────┤
872 │NULL (unknown value) │ │
873 │ │ <field │
874 │ │ name="column_name" │
875 │ │ xsi:nil="true" │
876 │ │ /> │
877 ├─────────────────────┼────────────────────────────────────────────┤
878 │ │ │
879 │ │ <field │
880 │ │ name="column_name"></field> │
881 ├─────────────────────┼────────────────────────────────────────────┤
882 │ │ │
883 │ │ <field │
884 │ │ name="column_name">NULL</field> │
885 └─────────────────────┴────────────────────────────────────────────┘
886 The output from the mysql client when run using the --xml option
887 also follows the preceding rules. (See the section called “MYSQL
888 CLIENT OPTIONS”.)
889
890 XML output from mysqldump includes the XML namespace, as shown
891 here:
892
893 shell> mysqldump --xml -u root world City
894 <?xml version="1.0"?>
895 <mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
896 <database name="world">
897 <table_structure name="City">
898 <field Field="ID" Type="int(11)" Null="NO" Key="PRI" Extra="auto_increment" />
899 <field Field="Name" Type="char(35)" Null="NO" Key="" Default="" Extra="" />
900 <field Field="CountryCode" Type="char(3)" Null="NO" Key="" Default="" Extra="" />
901 <field Field="District" Type="char(20)" Null="NO" Key="" Default="" Extra="" />
902 <field Field="Population" Type="int(11)" Null="NO" Key="" Default="0" Extra="" />
903 <key Table="City" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="ID"
904 Collation="A" Cardinality="4079" Null="" Index_type="BTREE" Comment="" />
905 <options Name="City" Engine="MyISAM" Version="10" Row_format="Fixed" Rows="4079"
906 Avg_row_length="67" Data_length="273293" Max_data_length="18858823439613951"
907 Index_length="43008" Data_free="0" Auto_increment="4080"
908 Create_time="2007-03-31 01:47:01" Update_time="2007-03-31 01:47:02"
909 Collation="latin1_swedish_ci" Create_options="" Comment="" />
910 </table_structure>
911 <table_data name="City">
912 <row>
913 <field name="ID">1</field>
914 <field name="Name">Kabul</field>
915 <field name="CountryCode">AFG</field>
916 <field name="District">Kabol</field>
917 <field name="Population">1780000</field>
918 </row>
919 ...
920 <row>
921 <field name="ID">4079</field>
922 <field name="Name">Rafah</field>
923 <field name="CountryCode">PSE</field>
924 <field name="District">Rafah</field>
925 <field name="Population">92020</field>
926 </row>
927 </table_data>
928 </database>
929 </mysqldump>
930 Filtering Options
931
932 The following options control which kinds of schema objects are written
933 to the dump file: by category, such as triggers or events; by name, for
934 example, choosing which databases and tables to dump; or even filtering
935 rows from the table data using a WHERE clause.
936
937 • --all-databases, -A Dump all tables in all databases. This is the
938 same as using the --databases option and naming all the databases
939 on the command line.
940
941 Note
942 See the --add-drop-database description for information about
943 an incompatibility of that option with --all-databases.
944 Prior to MySQL 8.0, the --routines and --events options for
945 mysqldump and mysqlpump were not required to include stored
946 routines and events when using the --all-databases option: The dump
947 included the mysql system database, and therefore also the
948 mysql.proc and mysql.event tables containing stored routine and
949 event definitions. As of MySQL 8.0, the mysql.event and mysql.proc
950 tables are not used. Definitions for the corresponding objects are
951 stored in data dictionary tables, but those tables are not dumped.
952 To include stored routines and events in a dump made using
953 --all-databases, use the --routines and --events options
954 explicitly.
955
956 • --databases, -B Dump several databases. Normally, mysqldump treats
957 the first name argument on the command line as a database name and
958 following names as table names. With this option, it treats all
959 name arguments as database names. CREATE DATABASE and USE
960 statements are included in the output before each new database.
961
962 This option may be used to dump the performance_schema database,
963 which normally is not dumped even with the --all-databases option.
964 (Also use the --skip-lock-tables option.)
965
966 Note
967 See the --add-drop-database description for information about
968 an incompatibility of that option with --databases.
969
970 • --events, -E Include Event Scheduler events for the dumped
971 databases in the output. This option requires the EVENT privileges
972 for those databases.
973
974 The output generated by using --events contains CREATE EVENT
975 statements to create the events.
976
977 • --ignore-error=error[,error]... Ignore the specified errors. The
978 option value is a list of comma-separated error numbers specifying
979 the errors to ignore during mysqldump execution. If the --force
980 option is also given to ignore all errors, --force takes
981 precedence.
982
983 • --ignore-table=db_name.tbl_name Do not dump the given table, which
984 must be specified using both the database and table names. To
985 ignore multiple tables, use this option multiple times. This option
986 also can be used to ignore views.
987
988 • --no-data, -d Do not write any table row information (that is, do
989 not dump table contents). This is useful if you want to dump only
990 the CREATE TABLE statement for the table (for example, to create an
991 empty copy of the table by loading the dump file).
992
993 • --routines, -R Include stored routines (procedures and functions)
994 for the dumped databases in the output. This option requires the
995 global SELECT privilege.
996
997 The output generated by using --routines contains CREATE PROCEDURE
998 and CREATE FUNCTION statements to create the routines.
999
1000 • --tables Override the --databases or -B option. mysqldump regards
1001 all name arguments following the option as table names.
1002
1003 • --triggers Include triggers for each dumped table in the output.
1004 This option is enabled by default; disable it with --skip-triggers.
1005
1006 To be able to dump a table's triggers, you must have the TRIGGER
1007 privilege for the table.
1008
1009 Multiple triggers are permitted. mysqldump dumps triggers in
1010 activation order so that when the dump file is reloaded, triggers
1011 are created in the same activation order. However, if a mysqldump
1012 dump file contains multiple triggers for a table that have the same
1013 trigger event and action time, an error occurs for attempts to load
1014 the dump file into an older server that does not support multiple
1015 triggers. (For a workaround, see Downgrade Notes[4]; you can
1016 convert triggers to be compatible with older servers.)
1017
1018 • --where='where_condition', -w 'where_condition' Dump only rows
1019 selected by the given WHERE condition. Quotes around the condition
1020 are mandatory if it contains spaces or other characters that are
1021 special to your command interpreter.
1022
1023 Examples:
1024
1025 --where="user='jimf'"
1026 -w"userid>1"
1027 -w"userid<1"
1028 Performance Options
1029
1030 The following options are the most relevant for the performance
1031 particularly of the restore operations. For large data sets, restore
1032 operation (processing the INSERT statements in the dump file) is the
1033 most time-consuming part. When it is urgent to restore data quickly,
1034 plan and test the performance of this stage in advance. For restore
1035 times measured in hours, you might prefer an alternative backup and
1036 restore solution, such as MySQL Enterprise Backup for InnoDB-only and
1037 mixed-use databases.
1038
1039 Performance is also affected by the transactional options, primarily
1040 for the dump operation.
1041
1042 • --column-statistics Add ANALYZE TABLE statements to the output to
1043 generate histogram statistics for dumped tables when the dump file
1044 is reloaded. This option is disabled by default because histogram
1045 generation for large tables can take a long time.
1046
1047 • --disable-keys, -K For each table, surround the INSERT statements
1048 with /*!40000 ALTER TABLE tbl_name DISABLE KEYS */; and /*!40000
1049 ALTER TABLE tbl_name ENABLE KEYS */; statements. This makes loading
1050 the dump file faster because the indexes are created after all rows
1051 are inserted. This option is effective only for nonunique indexes
1052 of MyISAM tables.
1053
1054 • --extended-insert, -e Write INSERT statements using multiple-row
1055 syntax that includes several VALUES lists. This results in a
1056 smaller dump file and speeds up inserts when the file is reloaded.
1057
1058 • --insert-ignore Write INSERT IGNORE statements rather than INSERT
1059 statements.
1060
1061 • --max-allowed-packet=value The maximum size of the buffer for
1062 client/server communication. The default is 24MB, the maximum is
1063 1GB.
1064
1065 • --net-buffer-length=value The initial size of the buffer for
1066 client/server communication. When creating multiple-row INSERT
1067 statements (as with the --extended-insert or --opt option),
1068 mysqldump creates rows up to --net-buffer-length bytes long. If you
1069 increase this variable, ensure that the MySQL server
1070 net_buffer_length system variable has a value at least this large.
1071
1072 • --network-timeout, -M Enable large tables to be dumped by setting
1073 --max-allowed-packet to its maximum value and network read and
1074 write timeouts to a large value. This option is enabled by default.
1075 To disable it, use --skip-network-timeout.
1076
1077 • --opt This option, enabled by default, is shorthand for the
1078 combination of --add-drop-table --add-locks --create-options
1079 --disable-keys --extended-insert --lock-tables --quick
1080 --set-charset. It gives a fast dump operation and produces a dump
1081 file that can be reloaded into a MySQL server quickly.
1082
1083 Because the --opt option is enabled by default, you only specify
1084 its converse, the --skip-opt to turn off several default settings.
1085 See the discussion of mysqldump option groups for information about
1086 selectively enabling or disabling a subset of the options affected
1087 by --opt.
1088
1089 • --quick, -q This option is useful for dumping large tables. It
1090 forces mysqldump to retrieve rows for a table from the server a row
1091 at a time rather than retrieving the entire row set and buffering
1092 it in memory before writing it out.
1093
1094 • --skip-opt See the description for the --opt option.
1095 Transactional Options
1096
1097 The following options trade off the performance of the dump operation,
1098 against the reliability and consistency of the exported data.
1099
1100 • --add-locks Surround each table dump with LOCK TABLES and UNLOCK
1101 TABLES statements. This results in faster inserts when the dump
1102 file is reloaded. See Section 8.2.5.1, “Optimizing INSERT
1103 Statements”.
1104
1105 • --flush-logs, -F Flush the MySQL server log files before starting
1106 the dump. This option requires the RELOAD privilege. If you use
1107 this option in combination with the --all-databases option, the
1108 logs are flushed for each database dumped. The exception is when
1109 using --lock-all-tables, --master-data, or --single-transaction: In
1110 this case, the logs are flushed only once, corresponding to the
1111 moment that all tables are locked by FLUSH TABLES WITH READ LOCK.
1112 If you want your dump and the log flush to happen at exactly the
1113 same moment, you should use --flush-logs together with
1114 --lock-all-tables, --master-data, or --single-transaction.
1115
1116 • --flush-privileges Add a FLUSH PRIVILEGES statement to the dump
1117 output after dumping the mysql database. This option should be used
1118 any time the dump contains the mysql database and any other
1119 database that depends on the data in the mysql database for proper
1120 restoration.
1121
1122 Because the dump file contains a FLUSH PRIVILEGES statement,
1123 reloading the file requires privileges sufficient to execute that
1124 statement.
1125
1126
1127 Note
1128 For upgrades to MySQL 5.7 or higher from older versions, do not
1129 use --flush-privileges. For upgrade instructions in this case,
1130 see Section 2.11.4, “Changes in MySQL 8.0”.
1131
1132 • --lock-all-tables, -x Lock all tables across all databases. This is
1133 achieved by acquiring a global read lock for the duration of the
1134 whole dump. This option automatically turns off
1135 --single-transaction and --lock-tables.
1136
1137 • --lock-tables, -l For each dumped database, lock all tables to be
1138 dumped before dumping them. The tables are locked with READ LOCAL
1139 to permit concurrent inserts in the case of MyISAM tables. For
1140 transactional tables such as InnoDB, --single-transaction is a much
1141 better option than --lock-tables because it does not need to lock
1142 the tables at all.
1143
1144 Because --lock-tables locks tables for each database separately,
1145 this option does not guarantee that the tables in the dump file are
1146 logically consistent between databases. Tables in different
1147 databases may be dumped in completely different states.
1148
1149 Some options, such as --opt, automatically enable --lock-tables. If
1150 you want to override this, use --skip-lock-tables at the end of the
1151 option list.
1152
1153 • --no-autocommit Enclose the INSERT statements for each dumped table
1154 within SET autocommit = 0 and COMMIT statements.
1155
1156 • --order-by-primary Dump each table's rows sorted by its primary
1157 key, or by its first unique index, if such an index exists. This is
1158 useful when dumping a MyISAM table to be loaded into an InnoDB
1159 table, but makes the dump operation take considerably longer.
1160
1161 • --shared-memory-base-name=name On Windows, the shared-memory name
1162 to use for connections made using shared memory to a local server.
1163 The default value is MYSQL. The shared-memory name is
1164 case-sensitive.
1165
1166 This option applies only if the server was started with the
1167 shared_memory system variable enabled to support shared-memory
1168 connections.
1169
1170 • --single-transaction This option sets the transaction isolation
1171 mode to REPEATABLE READ and sends a START TRANSACTION SQL statement
1172 to the server before dumping data. It is useful only with
1173 transactional tables such as InnoDB, because then it dumps the
1174 consistent state of the database at the time when START TRANSACTION
1175 was issued without blocking any applications.
1176
1177 When using this option, you should keep in mind that only InnoDB
1178 tables are dumped in a consistent state. For example, any MyISAM or
1179 MEMORY tables dumped while using this option may still change
1180 state.
1181
1182 While a --single-transaction dump is in process, to ensure a valid
1183 dump file (correct table contents and binary log coordinates), no
1184 other connection should use the following statements: ALTER TABLE,
1185 CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A
1186 consistent read is not isolated from those statements, so use of
1187 them on a table to be dumped can cause the SELECT that is performed
1188 by mysqldump to retrieve the table contents to obtain incorrect
1189 contents or fail.
1190
1191 The --single-transaction option and the --lock-tables option are
1192 mutually exclusive because LOCK TABLES causes any pending
1193 transactions to be committed implicitly.
1194
1195 To dump large tables, combine the --single-transaction option with
1196 the --quick option.
1197 Option Groups
1198
1199 • The --opt option turns on several settings that work together to
1200 perform a fast dump operation. All of these settings are on by
1201 default, because --opt is on by default. Thus you rarely if ever
1202 specify --opt. Instead, you can turn these settings off as a group
1203 by specifying --skip-opt, the optionally re-enable certain settings
1204 by specifying the associated options later on the command line.
1205
1206 • The --compact option turns off several settings that control
1207 whether optional statements and comments appear in the output.
1208 Again, you can follow this option with other options that re-enable
1209 certain settings, or turn all the settings on by using the
1210 --skip-compact form.
1211
1212 When you selectively enable or disable the effect of a group option,
1213 order is important because options are processed first to last. For
1214 example, --disable-keys --lock-tables --skip-opt would not have the
1215 intended effect; it is the same as --skip-opt by itself. Examples
1216
1217 To make a backup of an entire database:
1218
1219 mysqldump db_name > backup-file.sql
1220
1221 To load the dump file back into the server:
1222
1223 mysql db_name < backup-file.sql
1224
1225 Another way to reload the dump file:
1226
1227 mysql -e "source /path-to-backup/backup-file.sql" db_name
1228
1229 mysqldump is also very useful for populating databases by copying data
1230 from one MySQL server to another:
1231
1232 mysqldump --opt db_name | mysql --host=remote_host -C db_name
1233
1234 You can dump several databases with one command:
1235
1236 mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql
1237
1238 To dump all databases, use the --all-databases option:
1239
1240 mysqldump --all-databases > all_databases.sql
1241
1242 For InnoDB tables, mysqldump provides a way of making an online backup:
1243
1244 mysqldump --all-databases --master-data --single-transaction > all_databases.sql
1245
1246 This backup acquires a global read lock on all tables (using FLUSH
1247 TABLES WITH READ LOCK) at the beginning of the dump. As soon as this
1248 lock has been acquired, the binary log coordinates are read and the
1249 lock is released. If long updating statements are running when the
1250 FLUSH statement is issued, the MySQL server may get stalled until those
1251 statements finish. After that, the dump becomes lock free and does not
1252 disturb reads and writes on the tables. If the update statements that
1253 the MySQL server receives are short (in terms of execution time), the
1254 initial lock period should not be noticeable, even with many updates.
1255
1256 For point-in-time recovery (also known as “roll-forward,” when you need
1257 to restore an old backup and replay the changes that happened since
1258 that backup), it is often useful to rotate the binary log (see
1259 Section 5.4.4, “The Binary Log”) or at least know the binary log
1260 coordinates to which the dump corresponds:
1261
1262 mysqldump --all-databases --master-data=2 > all_databases.sql
1263
1264 Or:
1265
1266 mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql
1267
1268 The --master-data and --single-transaction options can be used
1269 simultaneously, which provides a convenient way to make an online
1270 backup suitable for use prior to point-in-time recovery if tables are
1271 stored using the InnoDB storage engine.
1272
1273 For more information on making backups, see Section 7.2, “Database
1274 Backup Methods”, and Section 7.3, “Example Backup and Recovery
1275 Strategy”.
1276
1277 • To select the effect of --opt except for some features, use the
1278 --skip option for each feature. To disable extended inserts and
1279 memory buffering, use --opt --skip-extended-insert --skip-quick.
1280 (Actually, --skip-extended-insert --skip-quick is sufficient
1281 because --opt is on by default.)
1282
1283 • To reverse --opt for all features except index disabling and table
1284 locking, use --skip-opt --disable-keys --lock-tables.
1285 Restrictions
1286
1287 mysqldump does not dump the performance_schema or sys schema by
1288 default. To dump any of these, name them explicitly on the command
1289 line. You can also name them with the --databases option. For
1290 performance_schema, also use the --skip-lock-tables option.
1291
1292 mysqldump does not dump the INFORMATION_SCHEMA schema.
1293
1294 mysqldump does not dump InnoDB CREATE TABLESPACE statements.
1295
1296 mysqldump does not dump the NDB Cluster ndbinfo information database.
1297
1298 mysqldump includes statements to recreate the general_log and
1299 slow_query_log tables for dumps of the mysql database. Log table
1300 contents are not dumped.
1301
1302 If you encounter problems backing up views due to insufficient
1303 privileges, see Section 25.9, “Restrictions on Views” for a workaround.
1304
1306 Copyright © 1997, 2021, Oracle and/or its affiliates.
1307
1308 This documentation is free software; you can redistribute it and/or
1309 modify it only under the terms of the GNU General Public License as
1310 published by the Free Software Foundation; version 2 of the License.
1311
1312 This documentation is distributed in the hope that it will be useful,
1313 but WITHOUT ANY WARRANTY; without even the implied warranty of
1314 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1315 General Public License for more details.
1316
1317 You should have received a copy of the GNU General Public License along
1318 with the program; if not, write to the Free Software Foundation, Inc.,
1319 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see
1320 http://www.gnu.org/licenses/.
1321
1322
1324 1. MySQL Shell dump utilities
1325 https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-dump-instance-schema.html
1326
1327 2. MySQL Shell load dump utilities
1328 https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-load-dump.html
1329
1330 3. here
1331 https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install.html
1332
1333 4. Downgrade Notes
1334 https://dev.mysql.com/doc/refman/5.7/en/downgrading-to-previous-series.html
1335
1337 For more information, please refer to the MySQL Reference Manual, which
1338 may already be installed locally and which is also available online at
1339 http://dev.mysql.com/doc/.
1340
1342 Oracle Corporation (http://dev.mysql.com/).
1343
1344
1345
1346MySQL 8.0 03/07/2021 MYSQLDUMP(1)