102
112
static char **defaults_argv= 0;
103
113
static char compatible_mode_normal_str[255];
104
114
/* Server supports character_set_results session variable? */
105
static bool server_supports_switching_charsets= true;
106
static uint32_t opt_compatible_mode= 0;
107
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
108
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
109
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
110
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
111
static uint opt_drizzle_port= 0, opt_master_data;
115
static my_bool server_supports_switching_charsets= TRUE;
116
static ulong opt_compatible_mode= 0;
117
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
119
#define MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
120
#define MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL 2
121
static uint opt_mysql_port= 0, opt_master_data;
112
122
static uint opt_slave_data;
113
123
static uint my_end_arg;
114
124
static int first_error=0;
115
static string extended_row;
125
static DYNAMIC_STRING extended_row;
116
126
FILE *md_result_file= 0;
117
127
FILE *stderror_file=0;
130
static char *shared_memory_base_name=0;
132
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
135
Dynamic_string wrapper functions. In this file use these
136
wrappers, they will terminate the process if there is
137
an allocation failure.
139
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
140
uint init_alloc, uint alloc_increment);
141
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src);
142
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str);
143
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
145
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
120
147
Constant for detection of default value of default_charset.
121
If default_charset is equal to drizzle_universal_client_charset, then
148
If default_charset is equal to mysql_universal_client_charset, then
122
149
it is the default value which assigned at the very beginning of main().
124
static const char *drizzle_universal_client_charset=
125
DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
151
static const char *mysql_universal_client_charset=
152
MYSQL_UNIVERSAL_CLIENT_CHARSET;
126
153
static char *default_charset;
127
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
128
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
154
static CHARSET_INFO *charset_info= &my_charset_latin1;
155
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
129
156
/* have we seen any VIEWs during table scanning? */
157
my_bool seen_views= 0;
131
158
const char *compatible_mode_names[]=
133
160
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
134
161
"MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
138
165
#define MASK_ANSI_QUOTES \
152
179
static struct my_option my_long_options[] =
154
181
{"all", 'a', "Deprecated. Use --create-options instead.",
155
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
182
(uchar**) &create_options, (uchar**) &create_options, 0, GET_BOOL, NO_ARG, 1,
157
184
{"all-databases", 'A',
158
185
"Dump all the databases. This will be same as --databases with all databases selected.",
159
(char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
186
(uchar**) &opt_alldbs, (uchar**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
161
188
{"all-tablespaces", 'Y',
162
189
"Dump all the tablespaces.",
163
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
190
(uchar**) &opt_alltspcs, (uchar**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
165
192
{"no-tablespaces", 'y',
166
193
"Do not dump any tablespace information.",
167
(char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
194
(uchar**) &opt_notspcs, (uchar**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
169
196
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
170
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
197
(uchar**) &opt_drop_database, (uchar**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
172
199
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
173
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
200
(uchar**) &opt_drop, (uchar**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
175
202
{"add-locks", OPT_LOCKS, "Add locks around insert statements.",
176
(char**) &opt_lock, (char**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
203
(uchar**) &opt_lock, (uchar**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
178
205
{"allow-keywords", OPT_KEYWORDS,
179
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
180
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
181
{"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
206
"Allow creation of column names that are keywords.", (uchar**) &opt_keywords,
207
(uchar**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
208
{"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
182
209
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
183
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
210
(uchar**) &opt_slave_apply, (uchar**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
184
211
0, 0, 0, 0, 0, 0},
185
212
{"character-sets-dir", OPT_CHARSETS_DIR,
186
"Directory where character sets are.", (char**) &charsets_dir,
187
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
213
"Directory where character sets are.", (uchar**) &charsets_dir,
214
(uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
188
215
{"comments", 'i', "Write additional information.",
189
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
216
(uchar**) &opt_comments, (uchar**) &opt_comments, 0, GET_BOOL, NO_ARG,
190
217
1, 0, 0, 0, 0, 0},
191
218
{"compatible", OPT_COMPATIBLE,
192
"Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.",
193
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
219
"Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. This option is ignored with earlier server versions.",
220
(uchar**) &opt_compatible_mode_str, (uchar**) &opt_compatible_mode_str, 0,
194
221
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
195
222
{"compact", OPT_COMPACT,
196
223
"Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks",
197
(char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
224
(uchar**) &opt_compact, (uchar**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
199
226
{"complete-insert", 'c', "Use complete insert statements.",
200
(char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
227
(uchar**) &opt_complete_insert, (uchar**) &opt_complete_insert, 0, GET_BOOL,
201
228
NO_ARG, 0, 0, 0, 0, 0, 0},
202
229
{"compress", 'C', "Use compression in server/client protocol.",
203
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
230
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
205
232
{"create-options", OPT_CREATE_OPTIONS,
206
"Include all DRIZZLE specific create options.",
207
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
233
"Include all MySQL specific create options.",
234
(uchar**) &create_options, (uchar**) &create_options, 0, GET_BOOL, NO_ARG, 1,
209
236
{"databases", 'B',
210
237
"To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.",
211
(char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
238
(uchar**) &opt_databases, (uchar**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
241
{"debug", '#', "This is a non-debug version. Catch this and exit",
242
0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
244
{"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
245
(uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
213
247
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
214
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
248
(uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
215
249
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
216
250
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
217
(char**) &debug_info_flag, (char**) &debug_info_flag,
251
(uchar**) &debug_info_flag, (uchar**) &debug_info_flag,
218
252
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
219
253
{"default-character-set", OPT_DEFAULT_CHARSET,
220
"Set the default character set.", (char**) &default_charset,
221
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
254
"Set the default character set.", (uchar**) &default_charset,
255
(uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
222
256
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
223
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
257
(uchar**) &opt_delayed, (uchar**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
225
259
{"delete-master-logs", OPT_DELETE_MASTER_LOGS,
226
260
"Delete logs on master after backup. This automatically enables --master-data.",
227
(char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
261
(uchar**) &opt_delete_master_logs, (uchar**) &opt_delete_master_logs, 0,
228
262
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
229
263
{"disable-keys", 'K',
230
"'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (char**) &opt_disable_keys,
231
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
232
{"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
264
"'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (uchar**) &opt_disable_keys,
265
(uchar**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
266
{"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
233
267
"This causes the binary log position and filename of the master to be "
234
268
"appended to the dumped data output. Setting the value to 1, will print"
235
269
"it as a CHANGE MASTER command in the dumped data output; if equal"
240
274
"- don't forget to read about --single-transaction below). In all cases "
241
275
"any action on logs will happen at the exact moment of the dump."
242
276
"Option automatically turns --lock-tables off.",
243
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
244
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
277
(uchar**) &opt_slave_data, (uchar**) &opt_slave_data, 0,
278
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
245
279
{"events", 'E', "Dump events.",
246
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
280
(uchar**) &opt_events, (uchar**) &opt_events, 0, GET_BOOL,
247
281
NO_ARG, 0, 0, 0, 0, 0, 0},
248
282
{"extended-insert", 'e',
249
283
"Allows utilization of the new, much faster INSERT syntax.",
250
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
284
(uchar**) &extended_insert, (uchar**) &extended_insert, 0, GET_BOOL, NO_ARG,
251
285
1, 0, 0, 0, 0, 0},
252
286
{"fields-terminated-by", OPT_FTB,
253
"Fields in the textfile are terminated by ...", (char**) &fields_terminated,
254
(char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
287
"Fields in the textfile are terminated by ...", (uchar**) &fields_terminated,
288
(uchar**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
255
289
{"fields-enclosed-by", OPT_ENC,
256
"Fields in the importfile are enclosed by ...", (char**) &enclosed,
257
(char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
290
"Fields in the importfile are enclosed by ...", (uchar**) &enclosed,
291
(uchar**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
258
292
{"fields-optionally-enclosed-by", OPT_O_ENC,
259
"Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
260
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
293
"Fields in the i.file are opt. enclosed by ...", (uchar**) &opt_enclosed,
294
(uchar**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
261
295
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
262
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
296
(uchar**) &escaped, (uchar**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
263
297
{"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
264
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
298
(uchar**) &opt_lock_all_tables, (uchar**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
265
299
0, 0, 0, 0, 0, 0},
266
300
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
267
301
"Note that if you dump many databases at once (using the option "
272
306
"to the moment all tables are locked. So if you want your dump and "
273
307
"the log flush to happen at the same exact moment you should use "
274
308
"--lock-all-tables or --master-data with --flush-logs",
275
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
309
(uchar**) &flush_logs, (uchar**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
277
311
{"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
278
"after dumping the DRIZZLE database. This option should be used any "
279
"time the dump contains the DRIZZLE database and any other database "
280
"that depends on the data in the DRIZZLE database for proper restore. ",
281
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
312
"after dumping the mysql database. This option should be used any "
313
"time the dump contains the mysql database and any other database "
314
"that depends on the data in the mysql database for proper restore. ",
315
(uchar**) &flush_privileges, (uchar**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
283
317
{"force", 'f', "Continue even if we get an sql-error.",
284
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
318
(uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG,
285
319
0, 0, 0, 0, 0, 0},
286
320
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
287
321
NO_ARG, 0, 0, 0, 0, 0, 0},
288
322
{"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
289
323
"VARBINARY, BLOB) in hexadecimal format.",
290
(char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
291
{"host", 'h', "Connect to host.", (char**) ¤t_host,
292
(char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
324
(uchar**) &opt_hex_blob, (uchar**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
325
{"host", 'h', "Connect to host.", (uchar**) ¤t_host,
326
(uchar**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
293
327
{"ignore-table", OPT_IGNORE_TABLE,
294
328
"Do not dump the specified table. To specify more than one table to ignore, "
295
329
"use the directive multiple times, once for each table. Each table must "
296
330
"be specified with both database and table names, e.g. --ignore-table=database.table",
297
331
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
298
{"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
332
{"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
299
333
"Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
300
(char**) &opt_include_master_host_port,
301
(char**) &opt_include_master_host_port,
334
(uchar**) &opt_include_master_host_port,
335
(uchar**) &opt_include_master_host_port,
302
336
0, GET_BOOL, NO_ARG,
303
337
0, 0, 0, 0, 0, 0},
304
338
{"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
305
(char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
339
(uchar**) &opt_ignore, (uchar**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
307
341
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
308
(char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
342
(uchar**) &lines_terminated, (uchar**) &lines_terminated, 0, GET_STR,
309
343
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
310
344
{"lock-all-tables", 'x', "Locks all tables across all databases. This "
311
345
"is achieved by taking a global read lock for the duration of the whole "
312
346
"dump. Automatically turns --single-transaction and --lock-tables off.",
313
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
347
(uchar**) &opt_lock_all_tables, (uchar**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
314
348
0, 0, 0, 0, 0, 0},
315
{"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
316
(char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
349
{"lock-tables", 'l', "Lock all tables for read.", (uchar**) &lock_tables,
350
(uchar**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
317
351
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
318
(char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
352
(uchar**) &log_error_file, (uchar**) &log_error_file, 0, GET_STR,
319
353
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
320
354
{"master-data", OPT_MASTER_DATA,
321
355
"This causes the binary log position and filename to be appended to the "
327
361
"- don't forget to read about --single-transaction below). In all cases "
328
362
"any action on logs will happen at the exact moment of the dump."
329
363
"Option automatically turns --lock-tables off.",
330
(char**) &opt_master_data, (char**) &opt_master_data, 0,
331
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
364
(uchar**) &opt_master_data, (uchar**) &opt_master_data, 0,
365
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
332
366
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
333
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
367
(uchar**) &opt_max_allowed_packet, (uchar**) &opt_max_allowed_packet, 0,
334
368
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
335
(int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
369
(longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
336
370
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
337
(char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
371
(uchar**) &opt_net_buffer_length, (uchar**) &opt_net_buffer_length, 0,
338
372
GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
339
373
MALLOC_OVERHEAD-1024, 1024, 0},
340
374
{"no-autocommit", OPT_AUTOCOMMIT,
341
375
"Wrap tables with autocommit/commit statements.",
342
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
376
(uchar**) &opt_autocommit, (uchar**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
343
377
0, 0, 0, 0, 0, 0},
344
378
{"no-create-db", 'n',
345
379
"'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
346
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
380
(uchar**) &opt_create_db, (uchar**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
348
382
{"no-create-info", 't', "Don't write table creation info.",
349
(char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
383
(uchar**) &opt_no_create_info, (uchar**) &opt_no_create_info, 0, GET_BOOL,
350
384
NO_ARG, 0, 0, 0, 0, 0, 0},
351
{"no-data", 'd', "No row information.", (char**) &opt_no_data,
352
(char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
385
{"no-data", 'd', "No row information.", (uchar**) &opt_no_data,
386
(uchar**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
353
387
{"no-set-names", 'N',
354
388
"Deprecated. Use --skip-set-charset instead.",
355
389
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
358
392
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
359
393
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
360
394
"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.",
361
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
395
(uchar**) &opt_order_by_primary, (uchar**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
362
396
{"password", 'p',
363
397
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
364
398
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
365
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
366
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
399
{"port", 'P', "Port number to use for connection.", (uchar**) &opt_mysql_port,
400
(uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
368
402
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
369
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
403
(uchar**) &quick, (uchar**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
370
404
{"quote-names",'Q', "Quote table and column names with backticks (`).",
371
(char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
405
(uchar**) &opt_quoted, (uchar**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
373
{"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
374
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
407
{"replace", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
408
(uchar**) &opt_replace_into, (uchar**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
376
410
{"result-file", 'r',
377
411
"Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).",
378
412
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
379
413
{"routines", 'R', "Dump stored routines (functions and procedures).",
380
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
414
(uchar**) &opt_routines, (uchar**) &opt_routines, 0, GET_BOOL,
381
415
NO_ARG, 0, 0, 0, 0, 0, 0},
382
416
{"set-charset", OPT_SET_CHARSET,
383
417
"Add 'SET NAMES default_character_set' to the output.",
384
(char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
418
(uchar**) &opt_set_charset, (uchar**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
386
420
{"set-variable", 'O',
387
421
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
388
422
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
424
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
425
"Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name,
426
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
390
429
Note that the combination --single-transaction --master-data
391
430
will give bullet-proof binlog position only if server >=4.1.3. That's the
401
440
"connection should use the following statements: ALTER TABLE, DROP "
402
441
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
403
442
"isolated from them. Option automatically turns off --lock-tables.",
404
(char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
443
(uchar**) &opt_single_transaction, (uchar**) &opt_single_transaction, 0,
405
444
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
406
445
{"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
407
(char**) &opt_dump_date, (char**) &opt_dump_date, 0,
446
(uchar**) &opt_dump_date, (uchar**) &opt_dump_date, 0,
408
447
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
409
448
{"skip-opt", OPT_SKIP_OPTIMIZATION,
410
449
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
411
450
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
413
452
"Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon.",
414
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
453
(uchar**) &path, (uchar**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
415
454
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
416
455
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
417
456
{"tz-utc", OPT_TZ_UTC,
418
457
"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.",
419
(char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
458
(uchar**) &opt_tz_utc, (uchar**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
420
459
#ifndef DONT_ALLOW_USER_CHANGE
421
460
{"user", 'u', "User for login if not current user.",
422
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
461
(uchar**) ¤t_user, (uchar**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
423
462
0, 0, 0, 0, 0, 0},
425
464
{"verbose", 'v', "Print info about the various stages.",
426
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
465
(uchar**) &verbose, (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
427
466
{"version",'V', "Output version information and exit.", 0, 0, 0,
428
467
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
429
468
{"where", 'w', "Dump only selected records; QUOTES mandatory!",
430
(char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
469
(uchar**) &where, (uchar**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
431
470
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
432
471
NO_ARG, 0, 0, 0, 0, 0, 0},
433
472
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
436
static const char *load_default_groups[]= { "drizzledump","client",0 };
475
static const char *load_default_groups[]= { "mysqldump","client",0 };
438
477
static void maybe_exit(int error);
439
478
static void die(int error, const char* reason, ...);
440
479
static void maybe_die(int error, const char* reason, ...);
441
480
static void write_header(FILE *sql_file, char *db_name);
442
static void print_value(FILE *file, DRIZZLE_RES *result, DRIZZLE_ROW row,
481
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
443
482
const char *prefix,const char *name,
444
483
int string_value);
445
484
static int dump_selected_tables(char *db, char **table_names, int tables);