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