-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
mysqldump.cc
6205 lines (5381 loc) · 216 KB
/
mysqldump.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Dump a table's contents and format to an ASCII file.
#define DUMP_VERSION "10.13"
#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string>
#include "client/client_priv.h"
#include "compression.h"
#include "m_ctype.h"
#include "m_string.h"
#include "map_helpers.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h"
#include "my_hostname.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_sys.h"
#include "my_systime.h" // GETDATE_DATE_TIME
#include "my_user.h"
#include "mysql.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "print_version.h"
#include "scope_guard.h"
#include "template_utils.h"
#include "typelib.h"
#include "welcome_copyright_notice.h" /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
/* Exit codes */
#define EX_USAGE 1
#define EX_MYSQLERR 2
#define EX_CONSCHECK 3
#define EX_EOM 4
#define EX_EOF 5 /* ferror for output file was got */
#define EX_ILLEGAL_TABLE 6
/* index into 'show fields from table' */
#define SHOW_FIELDNAME 0
#define SHOW_TYPE 1
#define SHOW_NULL 2
#define SHOW_DEFAULT 4
#define SHOW_EXTRA 5
/* Size of buffer for dump's select query */
#define QUERY_LENGTH 1536
/* Size of comment buffer. */
#define COMMENT_LENGTH 2048
/* ignore table flags */
#define IGNORE_NONE 0x00 /* no ignore */
#define IGNORE_DATA 0x01 /* don't dump data for this table */
#define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8mb4"
/* Maximum number of fields per table */
#define MAX_FIELDS 4000
/* One year in seconds */
#define LONG_TIMEOUT (3600UL * 24UL * 365UL)
/* First mysql version supporting column statistics. */
#define FIRST_COLUMN_STATISTICS_VERSION 80002
using std::string;
static void add_load_option(DYNAMIC_STRING *str, const char *option,
const char *option_value);
static char *alloc_query_str(size_t size);
static void field_escape(DYNAMIC_STRING *in, const char *from);
static bool verbose = false, opt_no_create_info = false, opt_no_data = false,
quick = true, extended_insert = true, lock_tables = true,
opt_force = false, flush_logs = false, flush_privileges = false,
opt_drop = true, opt_keywords = false, opt_lock = true,
opt_compress = false, create_options = true, opt_quoted = false,
opt_databases = false, opt_alldbs = false, opt_create_db = false,
opt_lock_all_tables = false, opt_set_charset = false,
opt_dump_date = true, opt_autocommit = false,
opt_disable_keys = true, opt_xml = false,
opt_delete_master_logs = false, opt_single_transaction = false,
opt_comments = false, opt_compact = false, opt_hex_blob = false,
opt_order_by_primary = false, opt_ignore = false,
opt_complete_insert = false, opt_drop_database = false,
opt_replace_into = false, opt_dump_triggers = false,
opt_routines = false, opt_tz_utc = true, opt_slave_apply = false,
opt_include_master_host_port = false, opt_events = false,
opt_comments_used = false, opt_alltspcs = false,
opt_notspcs = false, opt_drop_trigger = false,
opt_network_timeout = false, stats_tables_included = false,
column_statistics = false,
opt_show_create_table_skip_secondary_engine = false;
static bool insert_pat_inited = false, debug_info_flag = false,
debug_check_flag = false;
static ulong opt_max_allowed_packet, opt_net_buffer_length;
static MYSQL mysql_connection, *mysql = nullptr;
static DYNAMIC_STRING insert_pat;
static char *current_user = nullptr, *current_host = nullptr, *path = nullptr,
*fields_terminated = nullptr, *lines_terminated = nullptr,
*enclosed = nullptr, *opt_enclosed = nullptr, *escaped = nullptr,
*where = nullptr, *opt_compatible_mode_str = nullptr,
*opt_ignore_error = nullptr, *log_error_file = nullptr;
static MEM_ROOT argv_alloc{PSI_NOT_INSTRUMENTED, 512};
static bool ansi_mode = false; ///< Force the "ANSI" SQL_MODE.
/* Server supports character_set_results session variable? */
static bool server_supports_switching_charsets = true;
/**
Use double quotes ("") like in the standard to quote identifiers if true,
otherwise backticks (``, non-standard MySQL feature).
*/
static bool ansi_quotes_mode = false;
static uint opt_zstd_compress_level = default_zstd_compression_level;
static char *opt_compress_algorithm = nullptr;
#define MYSQL_OPT_SOURCE_DATA_EFFECTIVE_SQL 1
#define MYSQL_OPT_SOURCE_DATA_COMMENTED_SQL 2
#define MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
#define MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL 2
static uint opt_enable_cleartext_plugin = 0;
static bool using_opt_enable_cleartext_plugin = false;
static uint opt_mysql_port = 0, opt_master_data;
static uint opt_slave_data;
static ulong opt_long_query_time = 0;
static bool long_query_time_opt_provided = false;
static uint my_end_arg;
static char *opt_mysql_unix_port = nullptr;
static char *opt_bind_addr = nullptr;
static int first_error = 0;
#include "authentication_kerberos_clientopt-vars.h"
#include "caching_sha2_passwordopt-vars.h"
#include "multi_factor_passwordopt-vars.h"
#include "sslopt-vars.h"
FILE *md_result_file = nullptr;
FILE *stderror_file = nullptr;
const char *set_gtid_purged_mode_names[] = {"OFF", "AUTO", "ON", "COMMENTED",
NullS};
static TYPELIB set_gtid_purged_mode_typelib = {
array_elements(set_gtid_purged_mode_names) - 1, "",
set_gtid_purged_mode_names, nullptr};
static enum enum_set_gtid_purged_mode {
SET_GTID_PURGED_OFF = 0,
SET_GTID_PURGED_AUTO = 1,
SET_GTID_PURGED_ON = 2,
SET_GTID_PURGED_COMMENTED = 3
} opt_set_gtid_purged_mode = SET_GTID_PURGED_AUTO;
#if defined(_WIN32)
static char *shared_memory_base_name = 0;
#endif
static uint opt_protocol = 0;
static char *opt_plugin_dir = nullptr, *opt_default_auth = nullptr;
static bool opt_skip_gipk = false;
Prealloced_array<uint, 12> ignore_error(PSI_NOT_INSTRUMENTED);
static int parse_ignore_error();
/*
Dynamic_string wrapper functions. In this file use these
wrappers, they will terminate the process if there is
an allocation failure.
*/
static void init_dynamic_string_checked(DYNAMIC_STRING *str,
const char *init_str,
size_t init_alloc);
static void dynstr_append_checked(DYNAMIC_STRING *dest, const char *src);
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str);
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
size_t length);
static void dynstr_realloc_checked(DYNAMIC_STRING *str, size_t additional_size);
/*
Constant for detection of default value of default_charset.
If default_charset is equal to mysql_universal_client_charset, then
it is the default value which assigned at the very beginning of main().
*/
static const char *mysql_universal_client_charset =
MYSQL_UNIVERSAL_CLIENT_CHARSET;
static const char *default_charset;
static CHARSET_INFO *charset_info = &my_charset_latin1;
const char *default_dbug_option = "d:t:o,/tmp/mysqldump.trace";
/* have we seen any VIEWs during table scanning? */
bool seen_views = false;
collation_unordered_set<string> *ignore_table;
static struct my_option my_long_options[] = {
{"all-databases", 'A',
"Dump all the databases. This will be same as --databases with all "
"databases selected.",
&opt_alldbs, &opt_alldbs, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"all-tablespaces", 'Y', "Dump all the tablespaces.", &opt_alltspcs,
&opt_alltspcs, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"no-tablespaces", 'y', "Do not dump any tablespace information.",
&opt_notspcs, &opt_notspcs, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"add-drop-database", OPT_DROP_DATABASE,
"Add a DROP DATABASE before each create.", &opt_drop_database,
&opt_drop_database, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"add-drop-table", OPT_DROP, "Add a DROP TABLE before each create.",
&opt_drop, &opt_drop, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0,
nullptr},
{"add-drop-trigger", 0, "Add a DROP TRIGGER before each create.",
&opt_drop_trigger, &opt_drop_trigger, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
{"add-locks", OPT_LOCKS, "Add locks around INSERT statements.", &opt_lock,
&opt_lock, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0, nullptr},
{"allow-keywords", OPT_KEYWORDS,
"Allow creation of column names that are keywords.", &opt_keywords,
&opt_keywords, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"apply-replica-statements", OPT_MYSQLDUMP_REPLICA_APPLY,
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom "
"of dump.",
&opt_slave_apply, &opt_slave_apply, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
{"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY_DEPRECATED,
"This option is deprecated and will be removed in a future version. "
"Use apply-replica-statements instead.",
&opt_slave_apply, &opt_slave_apply, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
{"bind-address", 0, "IP address to bind to.", (uchar **)&opt_bind_addr,
(uchar **)&opt_bind_addr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr,
0, nullptr},
{"character-sets-dir", OPT_CHARSETS_DIR,
"Directory for character set files.", &charsets_dir, &charsets_dir,
nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"column-statistics", 0,
"Add an ANALYZE TABLE statement to regenerate any existing column "
"statistics.",
&column_statistics, &column_statistics, nullptr, GET_BOOL, NO_ARG, 1, 0, 0,
nullptr, 0, nullptr},
{"comments", 'i', "Write additional information.", &opt_comments,
&opt_comments, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0, nullptr},
{"compatible", OPT_COMPATIBLE,
"Change the dump to be compatible with a given mode. By default tables "
"are dumped in a format optimized for MySQL. The only legal mode is ANSI."
"Note: Requires MySQL server version 4.1.0 or higher. "
"This option is ignored with earlier server versions.",
&opt_compatible_mode_str, &opt_compatible_mode_str, nullptr, GET_STR,
REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"compact", OPT_COMPACT,
"Give less verbose output (useful for debugging). Disables structure "
"comments and header/footer constructs. Enables options --skip-add-"
"drop-table --skip-add-locks --skip-comments --skip-disable-keys "
"--skip-set-charset.",
&opt_compact, &opt_compact, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"complete-insert", 'c', "Use complete insert statements.",
&opt_complete_insert, &opt_complete_insert, nullptr, GET_BOOL, NO_ARG, 0,
0, 0, nullptr, 0, nullptr},
{"compress", 'C', "Use compression in server/client protocol.",
&opt_compress, &opt_compress, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr,
0, nullptr},
{"create-options", 'a', "Include all MySQL specific create options.",
&create_options, &create_options, nullptr, GET_BOOL, NO_ARG, 1, 0, 0,
nullptr, 0, nullptr},
{"databases", 'B',
"Dump several databases. Note the difference in usage; in this case no "
"tables are given. All name arguments are regarded as database names. "
"'USE db_name;' will be included in the output.",
&opt_databases, &opt_databases, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
#ifdef NDEBUG
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"debug-check", OPT_DEBUG_CHECK,
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"debug-info", OPT_DEBUG_INFO,
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
#else
{"debug", '#', "Output debug log.", &default_dbug_option,
&default_dbug_option, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"debug-check", OPT_DEBUG_CHECK,
"Check memory and open file usage at exit.", &debug_check_flag,
&debug_check_flag, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
&debug_info_flag, &debug_info_flag, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
#endif
{"default-character-set", OPT_DEFAULT_CHARSET,
"Set the default character set.", &default_charset, &default_charset,
nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"delete-source-logs", OPT_DELETE_SOURCE_LOGS,
"Rotate logs before the backup, equivalent to FLUSH LOGS, and purge "
"all old binary logs after the backup, equivalent to PURGE LOGS. This "
"automatically enables --source-data.",
&opt_delete_master_logs, &opt_delete_master_logs, nullptr, GET_BOOL,
NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"delete-master-logs", OPT_DELETE_MASTER_LOGS_DEPRECATED,
"This option is deprecated and will be removed in a future version. "
"Use delete-source-logs instead.",
&opt_delete_master_logs, &opt_delete_master_logs, nullptr, GET_BOOL,
NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"disable-keys", 'K',
"'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER "
"TABLE tb_name ENABLE KEYS */; will be put in the output.",
&opt_disable_keys, &opt_disable_keys, nullptr, GET_BOOL, NO_ARG, 1, 0, 0,
nullptr, 0, nullptr},
{"dump-replica", OPT_MYSQLDUMP_REPLICA_DATA,
"This causes the binary log position and filename of the source to be "
"appended to the dumped data output. Setting the value to 1, will print"
"it as a CHANGE MASTER command in the dumped data output; if equal"
" to 2, that command will be prefixed with a comment symbol. "
"This option will turn --lock-all-tables on, unless "
"--single-transaction is specified too (in which case a "
"global read lock is only taken a short time at the beginning of the dump "
"- don't forget to read about --single-transaction below). In all cases "
"any action on logs will happen at the exact moment of the dump."
"Option automatically turns --lock-tables off.",
&opt_slave_data, &opt_slave_data, nullptr, GET_UINT, OPT_ARG, 0, 0,
MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, nullptr, 0, nullptr},
{"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA_DEPRECATED,
"This option is deprecated and will be removed in a future version. "
"Use dump-replica instead.",
&opt_slave_data, &opt_slave_data, nullptr, GET_UINT, OPT_ARG, 0, 0,
MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, nullptr, 0, nullptr},
{"events", 'E', "Dump events.", &opt_events, &opt_events, nullptr, GET_BOOL,
NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"extended-insert", 'e',
"Use multiple-row INSERT syntax that include several VALUES lists.",
&extended_insert, &extended_insert, nullptr, GET_BOOL, NO_ARG, 1, 0, 0,
nullptr, 0, nullptr},
{"fields-terminated-by", OPT_FTB,
"Fields in the output file are terminated by the given string.",
&fields_terminated, &fields_terminated, nullptr, GET_STR, REQUIRED_ARG, 0,
0, 0, nullptr, 0, nullptr},
{"fields-enclosed-by", OPT_ENC,
"Fields in the output file are enclosed by the given character.",
&enclosed, &enclosed, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"fields-optionally-enclosed-by", OPT_O_ENC,
"Fields in the output file are optionally enclosed by the given "
"character.",
&opt_enclosed, &opt_enclosed, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
nullptr, 0, nullptr},
{"fields-escaped-by", OPT_ESC,
"Fields in the output file are escaped by the given character.", &escaped,
&escaped, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"flush-logs", 'F',
"Flush logs file in server before starting dump. "
"Note that if you dump many databases at once (using the option "
"--databases= or --all-databases), the logs will be flushed for "
"each database dumped. The exception is when using --lock-all-tables "
"or --source-data: "
"in this case the logs will be flushed only once, corresponding "
"to the moment all tables are locked. So if you want your dump and "
"the log flush to happen at the same exact moment you should use "
"--lock-all-tables or --source-data with --flush-logs.",
&flush_logs, &flush_logs, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"flush-privileges", OPT_ESC,
"Emit a FLUSH PRIVILEGES statement "
"after dumping the mysql database. This option should be used any "
"time the dump contains the mysql database and any other database "
"that depends on the data in the mysql database for proper restore. ",
&flush_privileges, &flush_privileges, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
{"force", 'f', "Continue even if we get an SQL error.", &opt_force,
&opt_force, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"help", '?', "Display this help message and exit.", nullptr, nullptr,
nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"hex-blob", OPT_HEXBLOB,
"Dump binary strings (BINARY, "
"VARBINARY, BLOB) in hexadecimal format.",
&opt_hex_blob, &opt_hex_blob, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr,
0, nullptr},
{"host", 'h', "Connect to host.", ¤t_host, ¤t_host, nullptr,
GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"ignore-error", OPT_MYSQLDUMP_IGNORE_ERROR,
"A comma-separated list of "
"error numbers to be ignored if encountered during dump.",
&opt_ignore_error, &opt_ignore_error, nullptr, GET_STR_ALLOC, REQUIRED_ARG,
0, 0, 0, nullptr, 0, nullptr},
{"ignore-table", OPT_IGNORE_TABLE,
"Do not dump the specified table. To specify more than one table to "
"ignore, "
"use the directive multiple times, once for each table. Each table must "
"be specified with both database and table names, e.g., "
"--ignore-table=database.table.",
nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"include-source-host-port", OPT_MYSQLDUMP_INCLUDE_SOURCE_HOST_PORT,
"Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' "
"in dump produced with --dump-replica.",
&opt_include_master_host_port, &opt_include_master_host_port, nullptr,
GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"include-master-host-port",
OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT_DEPRECATED,
"This option is deprecated and will be removed in a future version. "
"Use include-source-host-port instead.",
&opt_include_master_host_port, &opt_include_master_host_port, nullptr,
GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
&opt_ignore, &opt_ignore, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"lines-terminated-by", OPT_LTB,
"Lines in the output file are terminated by the given string.",
&lines_terminated, &lines_terminated, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
0, nullptr, 0, nullptr},
{"lock-all-tables", 'x',
"Locks all tables across all databases. This "
"is achieved by taking a global read lock for the duration of the whole "
"dump. Automatically turns --single-transaction and --lock-tables off.",
&opt_lock_all_tables, &opt_lock_all_tables, nullptr, GET_BOOL, NO_ARG, 0,
0, 0, nullptr, 0, nullptr},
{"lock-tables", 'l', "Lock all tables for read.", &lock_tables,
&lock_tables, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0, nullptr},
{"log-error", OPT_ERROR_LOG_FILE,
"Append warnings and errors to given file.", &log_error_file,
&log_error_file, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"mysqld-long-query-time", OPT_LONG_QUERY_TIME,
"Set long_query_time for the session of this dump. Ommitting flag means "
"using the server value.",
&opt_long_query_time, &opt_long_query_time, nullptr, GET_ULONG,
REQUIRED_ARG, 0, 0, LONG_TIMEOUT, nullptr, 0, nullptr},
{"source-data", OPT_SOURCE_DATA,
"This causes the binary log position and filename to be appended to the "
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
" to 2, that command will be prefixed with a comment symbol. "
"This option will turn --lock-all-tables on, unless "
"--single-transaction is specified too (in which case a "
"global read lock is only taken a short time at the beginning of the "
"dump; "
"don't forget to read about --single-transaction below). In all cases, "
"any action on logs will happen at the exact moment of the dump. "
"Option automatically turns --lock-tables off.",
&opt_master_data, &opt_master_data, nullptr, GET_UINT, OPT_ARG, 0, 0,
MYSQL_OPT_SOURCE_DATA_COMMENTED_SQL, nullptr, 0, nullptr},
{"master-data", OPT_MASTER_DATA_DEPRECATED,
"This option is deprecated and will be removed in a future version. "
"Use source-data instead.",
&opt_master_data, &opt_master_data, nullptr, GET_UINT, OPT_ARG, 0, 0,
MYSQL_OPT_SOURCE_DATA_COMMENTED_SQL, nullptr, 0, nullptr},
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
"The maximum packet length to send to or receive from server.",
&opt_max_allowed_packet, &opt_max_allowed_packet, nullptr, GET_ULONG,
REQUIRED_ARG, 24 * 1024 * 1024, 4096, (longlong)2L * 1024L * 1024L * 1024L,
nullptr, 1024, nullptr},
{"net_buffer_length", OPT_NET_BUFFER_LENGTH,
"The buffer size for TCP/IP and socket communication.",
&opt_net_buffer_length, &opt_net_buffer_length, nullptr, GET_ULONG,
REQUIRED_ARG, 1024 * 1024L - 1025, 4096, 16 * 1024L * 1024L, nullptr, 1024,
nullptr},
{"no-autocommit", OPT_AUTOCOMMIT,
"Wrap tables with autocommit/commit statements.", &opt_autocommit,
&opt_autocommit, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"no-create-db", 'n',
"Suppress the CREATE DATABASE ... IF EXISTS statement that normally is "
"output for each dumped database if --all-databases or --databases is "
"given.",
&opt_create_db, &opt_create_db, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
{"no-create-info", 't', "Don't write table creation info.",
&opt_no_create_info, &opt_no_create_info, nullptr, GET_BOOL, NO_ARG, 0, 0,
0, nullptr, 0, nullptr},
{"no-data", 'd', "No row information.", &opt_no_data, &opt_no_data, nullptr,
GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"no-set-names", 'N', "Same as --skip-set-charset.", nullptr, nullptr,
nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"opt", OPT_OPTIMIZE,
"Same as --add-drop-table, --add-locks, --create-options, --quick, "
"--extended-insert, --lock-tables, --set-charset, and --disable-keys. "
"Enabled by default, disable with --skip-opt.",
nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
"Sorts each table's rows by primary key, or first unique key, if such a "
"key exists. Useful when dumping a MyISAM table to be loaded into an "
"InnoDB table, but will make the dump itself take considerably longer.",
&opt_order_by_primary, &opt_order_by_primary, nullptr, GET_BOOL, NO_ARG, 0,
0, 0, nullptr, 0, nullptr},
#include "multi_factor_passwordopt-longopts.h"
#ifdef _WIN32
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"port", 'P', "Port number to use for connection.", &opt_mysql_port,
&opt_mysql_port, nullptr, GET_UINT, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"protocol", OPT_MYSQL_PROTOCOL,
"The protocol to use for connection (tcp, socket, pipe, memory).", nullptr,
nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"quick", 'q', "Don't buffer query, dump directly to stdout.", &quick,
&quick, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0, nullptr},
{"quote-names", 'Q', "Quote table and column names with backticks (`).",
&opt_quoted, &opt_quoted, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0,
nullptr},
{"replace", OPT_MYSQL_REPLACE_INTO,
"Use REPLACE INTO instead of INSERT INTO.", &opt_replace_into,
&opt_replace_into, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"result-file", 'r',
"Direct output to a given file. This option should be used in systems "
"(e.g., DOS, Windows) that use carriage-return linefeed pairs (\\r\\n) "
"to separate text lines. This option ensures that only a single newline "
"is used.",
nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"routines", 'R', "Dump stored routines (functions and procedures).",
&opt_routines, &opt_routines, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr,
0, nullptr},
{"set-charset", OPT_SET_CHARSET,
"Add 'SET NAMES default_character_set' to the output.", &opt_set_charset,
&opt_set_charset, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0, nullptr},
{"set-gtid-purged", OPT_SET_GTID_PURGED,
"Add 'SET @@GLOBAL.GTID_PURGED' to the output. Possible values for "
"this option are ON, COMMENTED, OFF and AUTO. If ON is used and GTIDs "
"are not enabled on the server, an error is generated. If COMMENTED is "
"used, 'SET @@GLOBAL.GTID_PURGED' is added as a comment. If OFF is "
"used, this option does nothing. If AUTO is used and GTIDs are enabled "
"on the server, 'SET @@GLOBAL.GTID_PURGED' is added to the output. "
"If GTIDs are disabled, AUTO does nothing. If no value is supplied "
"then the default (AUTO) value will be considered.",
nullptr, nullptr, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
#if defined(_WIN32)
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
"Base name of shared memory.", &shared_memory_base_name,
&shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0,
0},
#endif
/*
Note that the combination --single-transaction --master-data
will give bullet-proof binlog position only if server >=4.1.3. That's the
old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug.
*/
{"single-transaction", OPT_TRANSACTION,
"Creates a consistent snapshot by dumping all tables in a single "
"transaction. Works ONLY for tables stored in storage engines which "
"support multiversioning (currently only InnoDB does); the dump is NOT "
"guaranteed to be consistent for other storage engines. "
"While a --single-transaction dump is in process, to ensure a valid "
"dump file (correct table contents and binary log position), no other "
"connection should use the following statements: ALTER TABLE, DROP "
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
"isolated from them. Option automatically turns off --lock-tables.",
&opt_single_transaction, &opt_single_transaction, nullptr, GET_BOOL,
NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
&opt_dump_date, &opt_dump_date, nullptr, GET_BOOL, NO_ARG, 1, 0, 0,
nullptr, 0, nullptr},
{"skip-opt", OPT_SKIP_OPTIMIZATION,
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, "
"--quick, --extended-insert, --lock-tables, --set-charset, and "
"--disable-keys.",
nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"socket", 'S', "The socket file to use for connection.",
&opt_mysql_unix_port, &opt_mysql_unix_port, nullptr, GET_STR, REQUIRED_ARG,
0, 0, 0, nullptr, 0, nullptr},
#include "caching_sha2_passwordopt-longopts.h"
#include "sslopt-longopts.h"
{"tab", 'T',
"Create tab-separated textfile for each table to given path. (Create .sql "
"and .txt files.) NOTE: This only works if mysqldump is run on the same "
"machine as the mysqld server.",
&path, &path, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"tables", OPT_TABLES, "Overrides option --databases (-B).", nullptr,
nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"triggers", OPT_TRIGGERS, "Dump triggers for each dumped table.",
&opt_dump_triggers, &opt_dump_triggers, nullptr, GET_BOOL, NO_ARG, 1, 0, 0,
nullptr, 0, nullptr},
{"tz-utc", OPT_TZ_UTC,
"SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data "
"when a server has data in different time zones or data is being moved "
"between servers with different time zones.",
&opt_tz_utc, &opt_tz_utc, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0,
nullptr},
{"user", 'u', "User for login if not current user.", ¤t_user,
¤t_user, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"verbose", 'v', "Print info about the various stages.", &verbose, &verbose,
nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"version", 'V', "Output version information and exit.", nullptr, nullptr,
nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"where", 'w', "Dump only selected records. Quotes are mandatory.", &where,
&where, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"xml", 'X', "Dump a database as well formed XML.", nullptr, nullptr,
nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
&opt_plugin_dir, &opt_plugin_dir, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
nullptr, 0, nullptr},
{"default_auth", OPT_DEFAULT_AUTH,
"Default authentication client-side plugin to use.", &opt_default_auth,
&opt_default_auth, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
nullptr},
{"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN,
"Enable/disable the clear text authentication plugin.",
&opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin, nullptr,
GET_BOOL, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"network_timeout", 'M',
"Allows huge tables to be dumped by setting max_allowed_packet to maximum "
"value and net_read_timeout/net_write_timeout to large value.",
&opt_network_timeout, &opt_network_timeout, nullptr, GET_BOOL, NO_ARG, 1,
0, 0, nullptr, 0, nullptr},
{"show_create_table_skip_secondary_engine", 0,
"Controls whether SECONDARY_ENGINE CREATE TABLE clause should be dumped "
"or not. No effect on older servers that do not support the server side "
"option.",
&opt_show_create_table_skip_secondary_engine,
&opt_show_create_table_skip_secondary_engine, nullptr, GET_BOOL, NO_ARG, 0,
0, 0, nullptr, 0, nullptr},
{"compression-algorithms", 0,
"Use compression algorithm in server/client protocol. Valid values "
"are any combination of 'zstd','zlib','uncompressed'.",
&opt_compress_algorithm, &opt_compress_algorithm, nullptr, GET_STR,
REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"zstd-compression-level", 0,
"Use this compression level in the client/server protocol, in case "
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
"inclusive. Default is 3.",
&opt_zstd_compress_level, &opt_zstd_compress_level, nullptr, GET_UINT,
REQUIRED_ARG, 3, 1, 22, nullptr, 0, nullptr},
{"skip-generated-invisible-primary-key", 0,
"Controls whether generated invisible primary key and key column should "
"be dumped or not.",
&opt_skip_gipk, &opt_skip_gipk, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
nullptr, 0, nullptr},
#include "authentication_kerberos_clientopt-longopts.h"
{nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
0, nullptr, 0, nullptr}};
static const char *load_default_groups[] = {"mysqldump", "client", nullptr};
static void maybe_exit(int error);
static void die(int error, const char *reason, ...);
static void maybe_die(int error, const char *reason, ...);
static void write_header(FILE *sql_file, char *db_name);
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
const char *prefix, const char *name, int string_value);
static int dump_selected_tables(char *db, char **table_names, int tables);
static int dump_all_tables_in_db(char *db);
static int init_dumping_views(char *);
static int init_dumping_tables(char *);
static int init_dumping(char *, int init_func(char *));
static int dump_databases(char **);
static int dump_all_databases();
static char *quote_name(char *name, char *buff, bool force);
static const char *quote_name(const char *name, char *buff, bool force);
char check_if_ignore_table(const char *table_name, char *table_type);
bool is_infoschema_db(const char *db);
static char *primary_key_fields(const char *table_name);
static bool get_view_structure(char *table, char *db);
static bool dump_all_views_in_db(char *database);
static bool get_gtid_mode(MYSQL *mysql_con);
static int dump_all_tablespaces();
static int dump_tablespaces_for_tables(char *db, char **table_names,
int tables);
static int dump_tablespaces_for_databases(char **databases);
static int dump_tablespaces(char *ts_where);
static void print_comment(FILE *sql_file, bool is_error, const char *format,
...);
static void verbose_msg(const char *fmt, ...)
MY_ATTRIBUTE((format(printf, 1, 2)));
static char const *fix_identifier_with_newline(char const *object_name,
bool *freemem);
/*
Print the supplied message if in verbose mode
SYNOPSIS
verbose_msg()
fmt format specifier
... variable number of parameters
*/
static void verbose_msg(const char *fmt, ...) {
va_list args;
DBUG_TRACE;
if (!verbose) return;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fflush(stderr);
}
/*
exit with message if ferror(file)
SYNOPSIS
check_io()
file - checked file
*/
static void check_io(FILE *file) {
if (ferror(file) || errno == 5) die(EX_EOF, "Got errno %d on write", errno);
}
static void short_usage_sub(void) {
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
my_progname);
printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
}
static void usage(void) {
print_version();
puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
puts("Dumping structure and contents of MySQL databases and tables.");
short_usage_sub();
print_defaults("my", load_default_groups);
my_print_help(my_long_options);
my_print_variables(my_long_options);
} /* usage */
static void short_usage(void) {
short_usage_sub();
printf("For more options, use %s --help\n", my_progname);
}
static void get_safe_server_info(char *safe_server_info,
size_t safe_server_info_len) {
const char *server_info = mysql_get_server_info(&mysql_connection);
if (server_info == nullptr) {
safe_server_info[0] = 0;
return;
}
DBUG_EXECUTE_IF("server_version_injection_test", {
const char *payload = "8.0.0-injection_test\n\\! touch /tmp/xxx";
server_info = payload;
});
for (size_t i = 0; i < safe_server_info_len; ++i) {
// End of string.
if (server_info[i] == 0) {
safe_server_info[i] = 0;
return;
}
// Version may include only alphanumeric and punctuation characters.
// Cut off the rest of the string if incorrect character found.
if (!(isalnum(server_info[i]) || ispunct(server_info[i]))) {
safe_server_info[i] = 0;
fprintf(stderr,
"-- Warning: version string returned by server is incorrect.\n");
return;
}
safe_server_info[i] = server_info[i];
}
safe_server_info[safe_server_info_len - 1] = 0;
}
static void write_header(FILE *sql_file, char *db_name) {
if (opt_xml) {
fputs("<?xml version=\"1.0\"?>\n", sql_file);
/*
Schema reference. Allows use of xsi:nil for NULL values and
xsi:type to define an element's data type.
*/
fputs("<mysqldump ", sql_file);
fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", sql_file);
fputs(">\n", sql_file);
check_io(sql_file);
} else if (!opt_compact) {
print_comment(
sql_file, false, "-- MySQL dump %s Distrib %s, for %s (%s)\n--\n",
DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
bool freemem = false;
char const *text = fix_identifier_with_newline(db_name, &freemem);
char safe_server_info[SERVER_VERSION_LENGTH];
get_safe_server_info(safe_server_info, SERVER_VERSION_LENGTH);
print_comment(sql_file, false, "-- Host: %s Database: %s\n",
current_host ? current_host : "localhost", text);
if (freemem) my_free(const_cast<char *>(text));
print_comment(
sql_file, false,
"-- ------------------------------------------------------\n");
print_comment(sql_file, false, "-- Server version\t%s\n", safe_server_info);
if (opt_set_charset)
fprintf(
sql_file,
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS "
"*/;"
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
"\n/*!50503 SET NAMES %s */;\n",
default_charset);
if (opt_tz_utc) {
fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
}
if (stats_tables_included) {
fprintf(sql_file,
"/*!50606 SET "
"@OLD_INNODB_STATS_AUTO_RECALC=@@INNODB_STATS_AUTO_RECALC */;\n");
fprintf(sql_file,
"/*!50606 SET GLOBAL INNODB_STATS_AUTO_RECALC=OFF */;\n");
}
if (!path) {
fprintf(md_result_file,
"\
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n\
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n\
");
}
const char *mode1 = path ? "" : "NO_AUTO_VALUE_ON_ZERO";
const char *mode2 = ansi_mode ? "ANSI" : "";
const char *comma = *mode1 && *mode2 ? "," : "";
fprintf(sql_file,
"/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='%s%s%s' */;\n"
"/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n",
mode1, comma, mode2);
check_io(sql_file);
}
} /* write_header */
static void write_footer(FILE *sql_file) {
if (opt_xml) {
fputs("</mysqldump>\n", sql_file);
check_io(sql_file);
} else if (!opt_compact) {
if (opt_tz_utc)
fprintf(sql_file, "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
if (stats_tables_included)
fprintf(sql_file,
"/*!50606 SET GLOBAL "
"INNODB_STATS_AUTO_RECALC=@OLD_INNODB_STATS_AUTO_RECALC */;\n");
fprintf(sql_file, "\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n");
if (!path) {
fprintf(md_result_file,
"\
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n\
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
}
if (opt_set_charset)
fprintf(
sql_file,
"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"
"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
fprintf(sql_file, "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
fputs("\n", sql_file);
if (opt_dump_date) {
char time_str[20];
get_date(time_str, GETDATE_DATE_TIME, 0);
print_comment(sql_file, false, "-- Dump completed on %s\n", time_str);
} else
print_comment(sql_file, false, "-- Dump completed\n");
check_io(sql_file);
}
} /* write_footer */
static bool get_one_option(int optid, const struct my_option *opt,
char *argument) {
switch (optid) {
PARSE_COMMAND_LINE_PASSWORD_OPTION;
case 'r':
if (!(md_result_file =
my_fopen(argument, O_WRONLY | MY_FOPEN_BINARY, MYF(MY_WME))))
exit(1);
break;
case 'W':
#ifdef _WIN32
opt_protocol = MYSQL_PROTOCOL_PIPE;
#endif
break;
case 'N':
opt_set_charset = false;
break;
case 'T':
opt_disable_keys = false;
if (strlen(argument) >= FN_REFLEN) {
/*
This check is made because the some the file functions below
have FN_REFLEN sized stack allocated buffers and will cause
a crash even if the input destination buffer is large enough
to hold the output.
*/
die(EX_USAGE, "Input filename too long: %s", argument);
}
break;
case '#':
DBUG_PUSH(argument ? argument : default_dbug_option);
debug_check_flag = true;
break;
#include "sslopt-case.h"
#include "authentication_kerberos_clientopt-case.h"
case 'V':
print_version();
exit(0);
case 'X':
opt_xml = true;
extended_insert = opt_drop = opt_lock = opt_disable_keys =
opt_autocommit = opt_create_db = false;
break;
case 'i':
opt_comments_used = true;
break;
case 'I':
case '?':
usage();
exit(0);
case (int)OPT_MASTER_DATA_DEPRECATED:
CLIENT_WARN_DEPRECATED("--master-data", "--source-data");
[[fallthrough]];
case (int)OPT_SOURCE_DATA:
if (!argument) /* work like in old versions */
opt_master_data = MYSQL_OPT_SOURCE_DATA_EFFECTIVE_SQL;
break;
case (int)OPT_MYSQLDUMP_SLAVE_APPLY_DEPRECATED:
CLIENT_WARN_DEPRECATED("--apply-slave-statements",
"--apply-replica-statements");
break;
case (int)OPT_DELETE_MASTER_LOGS_DEPRECATED:
CLIENT_WARN_DEPRECATED("--delete-master-logs", "--delete-source-logs");
break;
case (int)OPT_MYSQLDUMP_SLAVE_DATA_DEPRECATED:
CLIENT_WARN_DEPRECATED("--dump-slave", "--dump-replica");
[[fallthrough]];
case (int)OPT_MYSQLDUMP_REPLICA_DATA:
if (!argument) /* work like in old versions */
opt_slave_data = MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL;
break;
case (int)OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT_DEPRECATED:
CLIENT_WARN_DEPRECATED("--include-master-host-port",
"--include-source-host-port");
break;
case (int)OPT_OPTIMIZE:
extended_insert = opt_drop = opt_lock = quick = create_options =
opt_disable_keys = lock_tables = opt_set_charset = true;
break;
case (int)OPT_SKIP_OPTIMIZATION:
extended_insert = opt_drop = opt_lock = quick = create_options =
opt_disable_keys = lock_tables = opt_set_charset = false;
break;
case (int)OPT_COMPACT:
if (opt_compact) {
opt_comments = opt_drop = opt_disable_keys = opt_lock = false;
opt_set_charset = false;
}
break;
case (int)OPT_TABLES:
opt_databases = false;
break;
case (int)OPT_IGNORE_TABLE: {
if (!strchr(argument, '.')) {
fprintf(stderr,
"Illegal use of option --ignore-table=<database>.<table>\n");
exit(1);
}