67
69
/* Size of buffer for dump's select query */
68
70
#define QUERY_LENGTH 1536
69
#define DRIZZLE_MAX_LINE_LENGTH 1024*1024L-1025
71
72
/* ignore table flags */
72
73
#define IGNORE_NONE 0x00 /* no ignore */
73
74
#define IGNORE_DATA 0x01 /* don't dump data for this table */
74
75
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
76
static void add_load_option(string &str, const char *option,
77
const char *option_value);
78
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
79
char **err_pos, uint32_t *err_len);
77
static void add_load_option(DYNAMIC_STRING *str, const char *option,
78
const char *option_value);
79
static ulong find_set(TYPELIB *lib, const char *x, uint length,
80
char **err_pos, uint *err_len);
81
static void field_escape(string &in, const char *from);
82
static bool verbose= false;
83
static bool opt_no_create_info= false;
84
static bool opt_no_data= false;
85
static bool opt_mysql= false;
86
static bool quick= true;
87
static bool extended_insert= true;
88
static bool ignore_errors= false;
89
static bool flush_logs= false;
90
static bool opt_drop= true;
91
static bool opt_keywords= false;
92
static bool opt_compress= false;
93
static bool opt_delayed= false;
94
static bool create_options= true;
95
static bool opt_quoted= false;
96
static bool opt_databases= false;
97
static bool opt_alldbs= false;
98
static bool opt_create_db= false;
99
static bool opt_lock_all_tables= false;
100
static bool opt_set_charset= false;
101
static bool opt_dump_date= true;
102
static bool opt_autocommit= false;
103
static bool opt_disable_keys= true;
104
static bool opt_xml= false;
105
static bool tty_password= false;
106
static bool opt_single_transaction= false;
107
static bool opt_comments= false;
108
static bool opt_compact= false;
109
static bool opt_hex_blob= false;
110
static bool opt_order_by_primary=false;
111
static bool opt_ignore= false;
112
static bool opt_complete_insert= false;
113
static bool opt_drop_database= false;
114
static bool opt_replace_into= false;
115
static bool opt_routines= false;
116
static bool opt_alltspcs= false;
117
static uint32_t show_progress_size= 0;
118
static uint64_t total_rows= 0;
119
static drizzle_st drizzle;
120
static drizzle_con_st dcon;
121
static string insert_pat;
122
static char *opt_password= NULL;
123
static char *current_user= NULL;
124
static char *current_host= NULL;
125
static char *path= NULL;
126
static char *fields_terminated= NULL;
127
static char *lines_terminated= NULL;
128
static char *enclosed= NULL;
129
static char *opt_enclosed= NULL;
130
static char *escaped= NULL;
131
static char *where= NULL;
132
static char *order_by= NULL;
133
static char *opt_compatible_mode_str= NULL;
134
static char *err_ptr= NULL;
135
static char **defaults_argv= NULL;
82
static void field_escape(DYNAMIC_STRING* in, const char *from);
83
static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
84
quick= 1, extended_insert= 1,
85
lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
86
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
87
opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
88
opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
89
opt_set_charset=0, opt_dump_date=1,
90
opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
91
opt_delete_master_logs=0, tty_password=0,
92
opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
93
opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
94
opt_complete_insert= 0, opt_drop_database= 0,
96
opt_routines=0, opt_tz_utc=1,
98
opt_include_master_host_port= 0,
100
opt_alltspcs=0, opt_notspcs= 0;
101
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
102
static ulong opt_max_allowed_packet, opt_net_buffer_length;
103
static MYSQL mysql_connection,*mysql=0;
104
static DYNAMIC_STRING insert_pat;
105
static char *opt_password=0,*current_user=0,
106
*current_host=0,*path=0,*fields_terminated=0,
107
*lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
108
*where=0, *order_by=0,
109
*opt_compatible_mode_str= 0,
111
*log_error_file= NULL;
112
static char **defaults_argv= 0;
136
113
static char compatible_mode_normal_str[255];
137
static uint32_t opt_compatible_mode= 0;
138
static uint32_t opt_drizzle_port= 0;
139
static int first_error= 0;
140
static string extended_row;
114
/* Server supports character_set_results session variable? */
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;
122
static uint opt_slave_data;
123
static uint my_end_arg;
124
static int first_error=0;
125
static DYNAMIC_STRING extended_row;
141
126
FILE *md_result_file= 0;
142
FILE *stderror_file= 0;
144
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
146
static const char *compatible_mode_names[]=
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);
147
Constant for detection of default value of default_charset.
148
If default_charset is equal to mysql_universal_client_charset, then
149
it is the default value which assigned at the very beginning of main().
151
static const char *mysql_universal_client_charset=
152
MYSQL_UNIVERSAL_CLIENT_CHARSET;
153
static char *default_charset;
154
static CHARSET_INFO *charset_info= &my_charset_latin1;
155
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
156
/* have we seen any VIEWs during table scanning? */
157
my_bool seen_views= 0;
158
const char *compatible_mode_names[]=
148
160
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
149
161
"MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
153
static TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
154
"", compatible_mode_names, NULL};
156
drizzled::hash_set<string> ignore_table;
158
static struct option my_long_options[] =
165
#define MASK_ANSI_QUOTES \
167
(1<<2) | /* POSTGRESQL */\
168
(1<<3) | /* ORACLE */\
169
(1<<4) | /* MSSQL */\
171
(1<<6) | /* MAXDB */\
174
TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
175
"", compatible_mode_names, NULL};
179
static struct my_option my_long_options[] =
160
181
{"all", 'a', "Deprecated. Use --create-options instead.",
161
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
182
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
163
184
{"all-databases", 'A',
164
"Dump all the databases. This will be same as --databases with all databases selected.",
165
(char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
185
"Dump all the databases. This will be same as --databases with all databases selected.",
186
(char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
167
188
{"all-tablespaces", 'Y',
168
"Dump all the tablespaces.",
169
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
189
"Dump all the tablespaces.",
190
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
192
{"no-tablespaces", 'y',
193
"Do not dump any tablespace information.",
194
(char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
171
196
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
172
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
197
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
174
199
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
175
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
200
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
202
{"add-locks", OPT_LOCKS, "Add locks around insert statements.",
203
(char**) &opt_lock, (char**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
177
205
{"allow-keywords", OPT_KEYWORDS,
178
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
179
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
206
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
207
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
208
{"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
209
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
210
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
212
{"character-sets-dir", OPT_CHARSETS_DIR,
213
"Directory where character sets are.", (char**) &charsets_dir,
214
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
180
215
{"comments", 'i', "Write additional information.",
181
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
216
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
183
218
{"compatible", OPT_COMPATIBLE,
184
"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.",
185
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
186
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 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
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
221
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
187
222
{"compact", OPT_COMPACT,
188
"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",
189
(char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
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",
224
(char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
191
226
{"complete-insert", 'c', "Use complete insert statements.",
192
(char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
193
NO_ARG, 0, 0, 0, 0, 0, 0},
227
(char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
228
NO_ARG, 0, 0, 0, 0, 0, 0},
194
229
{"compress", 'C', "Use compression in server/client protocol.",
195
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
230
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
197
232
{"create-options", OPT_CREATE_OPTIONS,
198
"Include all DRIZZLE specific create options.",
199
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
233
"Include all MySQL specific create options.",
234
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
201
236
{"databases", 'B',
202
"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.",
203
(char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
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.",
238
(char**) &opt_databases, (char**) &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", (char**) &default_dbug_option,
245
(char**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
247
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
248
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
249
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
250
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
251
(char**) &debug_info_flag, (char**) &debug_info_flag,
252
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
253
{"default-character-set", OPT_DEFAULT_CHARSET,
254
"Set the default character set.", (char**) &default_charset,
255
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
205
256
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
206
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
257
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
259
{"delete-master-logs", OPT_DELETE_MASTER_LOGS,
260
"Delete logs on master after backup. This automatically enables --master-data.",
261
(char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
262
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
208
263
{"disable-keys", 'K',
209
"'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
210
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
264
"'/*!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,
265
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
266
{"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
267
"This causes the binary log position and filename of the master to be "
268
"appended to the dumped data output. Setting the value to 1, will print"
269
"it as a CHANGE MASTER command in the dumped data output; if equal"
270
" to 2, that command will be prefixed with a comment symbol. "
271
"This option will turn --lock-all-tables on, unless "
272
"--single-transaction is specified too (in which case a "
273
"global read lock is only taken a short time at the beginning of the dump "
274
"- don't forget to read about --single-transaction below). In all cases "
275
"any action on logs will happen at the exact moment of the dump."
276
"Option automatically turns --lock-tables off.",
277
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
278
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
279
{"events", 'E', "Dump events.",
280
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
281
NO_ARG, 0, 0, 0, 0, 0, 0},
211
282
{"extended-insert", 'e',
212
"Allows utilization of the new, much faster INSERT syntax.",
213
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
283
"Allows utilization of the new, much faster INSERT syntax.",
284
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
215
286
{"fields-terminated-by", OPT_FTB,
216
"Fields in the textfile are terminated by ...", (char**) &fields_terminated,
217
(char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
287
"Fields in the textfile are terminated by ...", (char**) &fields_terminated,
288
(char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
218
289
{"fields-enclosed-by", OPT_ENC,
219
"Fields in the importfile are enclosed by ...", (char**) &enclosed,
220
(char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
290
"Fields in the importfile are enclosed by ...", (char**) &enclosed,
291
(char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
221
292
{"fields-optionally-enclosed-by", OPT_O_ENC,
222
"Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
223
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
293
"Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
294
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
224
295
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
225
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
296
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
297
{"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
298
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
226
300
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
227
"Note that if you dump many databases at once (using the option "
228
"--databases= or --all-databases), the logs will be flushed for "
229
"each database dumped. The exception is when using --lock-all-tables "
230
"in this case the logs will be flushed only once, corresponding "
231
"to the moment all tables are locked. So if you want your dump and "
232
"the log flush to happen at the same exact moment you should use "
233
"--lock-all-tables or --flush-logs",
234
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
301
"Note that if you dump many databases at once (using the option "
302
"--databases= or --all-databases), the logs will be flushed for "
303
"each database dumped. The exception is when using --lock-all-tables "
305
"in this case the logs will be flushed only once, corresponding "
306
"to the moment all tables are locked. So if you want your dump and "
307
"the log flush to happen at the same exact moment you should use "
308
"--lock-all-tables or --master-data with --flush-logs",
309
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
311
{"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
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
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
236
317
{"force", 'f', "Continue even if we get an sql-error.",
237
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
318
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
239
320
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
240
NO_ARG, 0, 0, 0, 0, 0, 0},
321
NO_ARG, 0, 0, 0, 0, 0, 0},
241
322
{"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
242
323
"VARBINARY, BLOB) in hexadecimal format.",
243
(char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
324
(char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
244
325
{"host", 'h', "Connect to host.", (char**) ¤t_host,
245
(char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
326
(char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
246
327
{"ignore-table", OPT_IGNORE_TABLE,
247
"Do not dump the specified table. To specify more than one table to ignore, "
248
"use the directive multiple times, once for each table. Each table must "
249
"be specified with both database and table names, e.g. --ignore-table=database.table",
250
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
328
"Do not dump the specified table. To specify more than one table to ignore, "
329
"use the directive multiple times, once for each table. Each table must "
330
"be specified with both database and table names, e.g. --ignore-table=database.table",
331
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
332
{"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
333
"Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
334
(char**) &opt_include_master_host_port,
335
(char**) &opt_include_master_host_port,
251
338
{"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
252
(char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
339
(char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
254
341
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
255
(char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
256
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
342
(char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
343
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
257
344
{"lock-all-tables", 'x', "Locks all tables across all databases. This "
258
"is achieved by taking a global read lock for the duration of the whole "
259
"dump. Automatically turns --single-transaction and --lock-tables off.",
260
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
262
{"mysql", 'm', N_("Use MySQL Protocol."),
263
(char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
345
"is achieved by taking a global read lock for the duration of the whole "
346
"dump. Automatically turns --single-transaction and --lock-tables off.",
347
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
349
{"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
350
(char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
351
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
352
(char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
353
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
354
{"master-data", OPT_MASTER_DATA,
355
"This causes the binary log position and filename to be appended to the "
356
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
357
" to 2, that command will be prefixed with a comment symbol. "
358
"This option will turn --lock-all-tables on, unless "
359
"--single-transaction is specified too (in which case a "
360
"global read lock is only taken a short time at the beginning of the dump "
361
"- don't forget to read about --single-transaction below). In all cases "
362
"any action on logs will happen at the exact moment of the dump."
363
"Option automatically turns --lock-tables off.",
364
(char**) &opt_master_data, (char**) &opt_master_data, 0,
365
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
366
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
367
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
368
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
369
(longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
370
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
371
(char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
372
GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
373
MALLOC_OVERHEAD-1024, 1024, 0},
265
374
{"no-autocommit", OPT_AUTOCOMMIT,
266
"Wrap tables with autocommit/commit statements.",
267
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
375
"Wrap tables with autocommit/commit statements.",
376
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
269
378
{"no-create-db", 'n',
270
"'CREATE DATABASE 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.}.",
271
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
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.}.",
380
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
273
382
{"no-create-info", 't', "Don't write table creation info.",
274
(char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
275
NO_ARG, 0, 0, 0, 0, 0, 0},
383
(char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
384
NO_ARG, 0, 0, 0, 0, 0, 0},
276
385
{"no-data", 'd', "No row information.", (char**) &opt_no_data,
277
(char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
386
(char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
278
387
{"no-set-names", 'N',
279
"Deprecated. Use --skip-set-charset instead.",
280
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
388
"Deprecated. Use --skip-set-charset instead.",
389
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
281
390
{"opt", OPT_OPTIMIZE,
282
"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.",
283
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
391
"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.",
392
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
284
393
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
285
"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.",
286
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
288
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
289
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
290
{"port", 'p', "Port number to use for connection.",
291
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
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.",
395
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
397
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
398
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
399
{"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
400
(char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
292
402
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
293
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
403
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
294
404
{"quote-names",'Q', "Quote table and column names with backticks (`).",
295
(char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
297
{"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
298
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
405
(char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
407
{"replace", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
408
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
300
410
{"result-file", 'r',
301
"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).",
302
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
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).",
412
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
303
413
{"routines", 'R', "Dump stored routines (functions and procedures).",
304
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
305
NO_ARG, 0, 0, 0, 0, 0, 0},
414
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
415
NO_ARG, 0, 0, 0, 0, 0, 0},
416
{"set-charset", OPT_SET_CHARSET,
417
"Add 'SET NAMES default_character_set' to the output.",
418
(char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
420
{"set-variable", 'O',
421
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
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.", (char**) &shared_memory_base_name, (char**) &shared_memory_base_name,
426
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
429
Note that the combination --single-transaction --master-data
430
will give bullet-proof binlog position only if server >=4.1.3. That's the
431
old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug.
306
433
{"single-transaction", OPT_TRANSACTION,
307
"Creates a consistent snapshot by dumping all tables in a single "
308
"transaction. Works ONLY for tables stored in storage engines which "
309
"support multiversioning (currently only InnoDB does); the dump is NOT "
310
"guaranteed to be consistent for other storage engines. "
311
"While a --single-transaction dump is in process, to ensure a valid "
312
"dump file (correct table contents), no other "
313
"connection should use the following statements: ALTER TABLE, DROP "
314
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
315
"isolated from them. Option automatically turns off --lock-tables.",
316
(char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
317
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
434
"Creates a consistent snapshot by dumping all tables in a single "
435
"transaction. Works ONLY for tables stored in storage engines which "
436
"support multiversioning (currently only InnoDB does); the dump is NOT "
437
"guaranteed to be consistent for other storage engines. "
438
"While a --single-transaction dump is in process, to ensure a valid "
439
"dump file (correct table contents and binary log position), no other "
440
"connection should use the following statements: ALTER TABLE, DROP "
441
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
442
"isolated from them. Option automatically turns off --lock-tables.",
443
(char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
444
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
318
445
{"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
319
(char**) &opt_dump_date, (char**) &opt_dump_date, 0,
320
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
446
(char**) &opt_dump_date, (char**) &opt_dump_date, 0,
447
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
321
448
{"skip-opt", OPT_SKIP_OPTIMIZATION,
322
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
323
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
449
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
450
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
325
"Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if drizzledump is run on the same machine as the drizzled daemon.",
326
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
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.",
453
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
327
454
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
328
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
329
{"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
330
(char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
331
10000, 0, 0, 0, 0, 0},
455
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
456
{"tz-utc", OPT_TZ_UTC,
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.",
458
(char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
459
#ifndef DONT_ALLOW_USER_CHANGE
332
460
{"user", 'u', "User for login if not current user.",
333
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
461
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
335
464
{"verbose", 'v', "Print info about the various stages.",
336
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
465
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
337
466
{"version",'V', "Output version information and exit.", 0, 0, 0,
338
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
467
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
339
468
{"where", 'w', "Dump only selected records; QUOTES mandatory!",
340
(char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
469
(char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
341
470
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
342
NO_ARG, 0, 0, 0, 0, 0, 0},
471
NO_ARG, 0, 0, 0, 0, 0, 0},
343
472
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
346
static const char *load_default_groups[]= { "drizzledump","client",0 };
475
static const char *load_default_groups[]= { "mysqldump","client",0 };
348
477
static void maybe_exit(int error);
349
478
static void die(int error, const char* reason, ...);
350
479
static void maybe_die(int error, const char* reason, ...);
351
480
static void write_header(FILE *sql_file, char *db_name);
352
static void print_value(FILE *file, drizzle_result_st *result,
353
drizzle_row_t row, const char *prefix, const char *name,
481
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
482
const char *prefix,const char *name,
354
483
int string_value);
355
static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row,
357
484
static int dump_selected_tables(char *db, char **table_names, int tables);
358
485
static int dump_all_tables_in_db(char *db);
359
486
static int init_dumping_tables(char *);
360
487
static int init_dumping(char *, int init_func(char*));
361
488
static int dump_databases(char **);
362
489
static int dump_all_databases(void);
363
static char *quote_name(const char *name, char *buff, bool force);
490
static char *quote_name(const char *name, char *buff, my_bool force);
364
491
char check_if_ignore_table(const char *table_name, char *table_type);
365
492
static char *primary_key_fields(const char *table_name);
494
#include <help_start.h>
368
497
Print the supplied message if in verbose mode
373
... variable number of parameters
502
... variable number of parameters
375
505
static void verbose_msg(const char *fmt, ...)
508
DBUG_ENTER("verbose_msg");
383
513
va_start(args, fmt);
384
514
vfprintf(stderr, fmt, args);
389
521
exit with message if ferror(file)
396
528
static void check_io(FILE *file)
398
530
if (ferror(file))
399
die(EX_EOF, _("Got errno %d on write"), errno);
531
die(EX_EOF, "Got errno %d on write", errno);
402
534
static void print_version(void)
404
printf(_("%s Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
405
VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
536
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
537
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
406
538
} /* print_version */
409
541
static void short_usage_sub(void)
411
printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
412
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
413
internal::my_progname);
414
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
543
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
544
printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
546
printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
418
550
static void usage(void)
422
puts(_("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"));
423
puts(_("Dumps definitions and data from a Drizzle database server"));
553
puts("By Igor Romanenko, Monty, Jani & Sinisa");
554
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
555
puts("Dumping definition and data mysql database or table");
424
556
short_usage_sub();
425
internal::print_defaults("drizzle",load_default_groups);
557
print_defaults("my",load_default_groups);
426
558
my_print_help(my_long_options);
427
559
my_print_variables(my_long_options);
2400
2791
different case (e.g. T1 vs t1)
2403
pointer to the table name
2794
pointer to the table name
2407
static char *get_actual_table_name(const char *old_table_name,
2408
drizzled::memory::Root *root)
2798
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2411
drizzle_result_st result;
2413
char query[50 + 2*DRIZZLE_MAX_TABLE_SIZE];
2801
MYSQL_RES *table_res;
2803
char query[50 + 2*NAME_LEN];
2414
2804
char show_name_buff[FN_REFLEN];
2805
DBUG_ENTER("get_actual_table_name");
2418
2807
/* Check memory for quote_for_like() */
2419
assert(2*sizeof(old_table_name) < sizeof(show_name_buff));
2808
DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff));
2420
2809
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2421
2810
quote_for_like(old_table_name, show_name_buff));
2423
if (drizzleclient_query_with_error_report(&dcon, &result, query, false))
2812
if (mysql_query_with_error_report(mysql, 0, query))
2426
num_rows= drizzle_result_row_count(&result);
2815
if ((table_res= mysql_store_result(mysql)))
2432
TODO-> Return all matching rows
2434
row= drizzle_row_next(&result);
2435
lengths= drizzle_row_field_sizes(&result);
2436
name= strmake_root(root, row[0], lengths[0]);
2817
my_ulonglong num_rows= mysql_num_rows(table_res);
2823
TODO: Return all matching rows
2825
row= mysql_fetch_row(table_res);
2826
lengths= mysql_fetch_lengths(table_res);
2827
name= strmake_root(root, row[0], lengths[0]);
2829
mysql_free_result(table_res);
2438
drizzle_result_free(&result);
2831
DBUG_PRINT("exit", ("new_table_name: %s", name));
2444
2836
static int dump_selected_tables(char *db, char **table_names, int tables)
2446
drizzled::memory::Root root;
2838
char table_buff[NAME_LEN*2+3];
2839
DYNAMIC_STRING lock_tables_query;
2447
2841
char **dump_tables, **pos, **end;
2448
drizzle_result_st result;
2449
drizzle_return_t ret;
2842
DBUG_ENTER("dump_selected_tables");
2452
2844
if (init_dumping(db, init_dumping_tables))
2455
init_alloc_root(&root, 8192);
2847
init_alloc_root(&root, 8192, 0);
2456
2848
if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2457
die(EX_EOM, _("alloc_root failure."));
2849
die(EX_EOM, "alloc_root failure.");
2851
init_dynamic_string_checked(&lock_tables_query, "LOCK TABLES ", 256, 1024);
2459
2852
for (; tables > 0 ; tables-- , table_names++)
2461
2854
/* the table name passed on commandline may be wrong case */
2462
2855
if ((*pos= get_actual_table_name(*table_names, &root)))
2857
/* Add found table name to lock_tables_query */
2860
dynstr_append_checked(&lock_tables_query, quote_name(*pos, table_buff, 1));
2861
dynstr_append_checked(&lock_tables_query, " READ /*!32311 LOCAL */,");
2468
2867
if (!ignore_errors)
2869
dynstr_free(&lock_tables_query);
2470
2870
free_root(&root, MYF(0));
2472
maybe_die(EX_ILLEGAL_TABLE, _("Couldn't find table: \"%s\""), *table_names);
2872
maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
2473
2873
/* We shall countinue here, if --force was given */
2880
if (mysql_real_query(mysql, lock_tables_query.str,
2881
lock_tables_query.length-1))
2885
dynstr_free(&lock_tables_query);
2886
free_root(&root, MYF(0));
2888
DB_error(mysql, "when doing LOCK TABLES");
2889
/* We shall countinue here, if --force was given */
2892
dynstr_free(&lock_tables_query);
2478
2893
if (flush_logs)
2480
if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
2481
ret != DRIZZLE_RETURN_OK)
2895
if (mysql_refresh(mysql, REFRESH_LOG))
2483
2897
if (!ignore_errors)
2484
2898
free_root(&root, MYF(0));
2485
DB_error(&result, ret, _("when doing refresh"));
2486
/* We shall countinue here, if --force was given */
2899
DB_error(mysql, "when doing refresh");
2489
drizzle_result_free(&result);
2901
/* We shall countinue here, if --force was given */
2492
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2904
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
2494
2906
/* Dump each selected table */
2495
2907
for (pos= dump_tables; pos < end; pos++)
2909
DBUG_PRINT("info",("Dumping table %s", *pos));
2496
2910
dump_table(*pos, db);
2498
2913
free_root(&root, MYF(0));
2914
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2503
2918
fputs("</database>\n", md_result_file);
2504
2919
check_io(md_result_file);
2922
VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
2507
2924
} /* dump_selected_tables */
2509
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
2927
static int do_show_master_status(MYSQL *mysql_con)
2931
const char *comment_prefix=
2932
(opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2933
if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS"))
2939
row= mysql_fetch_row(master);
2940
if (row && row[0] && row[1])
2942
/* SHOW MASTER STATUS reports file and position */
2944
fprintf(md_result_file,
2945
"\n--\n-- Position to start replication or point-in-time "
2946
"recovery from\n--\n\n");
2947
fprintf(md_result_file,
2948
"%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n",
2949
comment_prefix, row[0], row[1]);
2950
check_io(md_result_file);
2952
else if (!ignore_errors)
2954
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2955
my_printf_error(0, "Error: Binlogging on server not active",
2957
mysql_free_result(master);
2958
maybe_exit(EX_MYSQLERR);
2961
mysql_free_result(master);
2966
static int do_stop_slave_sql(MYSQL *mysql_con)
2969
/* We need to check if the slave sql is running in the first place */
2970
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2974
MYSQL_ROW row= mysql_fetch_row(slave);
2977
/* if SLAVE SQL is not running, we don't stop it */
2978
if (!strcmp(row[11],"No"))
2980
mysql_free_result(slave);
2981
/* Silently assume that they don't have the slave running */
2986
mysql_free_result(slave);
2988
/* now, stop slave if running */
2989
if (mysql_query_with_error_report(mysql_con, 0, "STOP SLAVE SQL_THREAD"))
2995
static int add_stop_slave(void)
2998
fprintf(md_result_file,
2999
"\n--\n-- stop slave statement to make a recovery dump)\n--\n\n");
3000
fprintf(md_result_file, "STOP SLAVE;\n");
3004
static int add_slave_statements(void)
3007
fprintf(md_result_file,
3008
"\n--\n-- start slave statement to make a recovery dump)\n--\n\n");
3009
fprintf(md_result_file, "START SLAVE;\n");
3013
static int do_show_slave_status(MYSQL *mysql_con)
3016
const char *comment_prefix=
3017
(opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
3018
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
3022
/* SHOW SLAVE STATUS reports nothing and --force is not enabled */
3023
my_printf_error(0, "Error: Slave not set up", MYF(0));
3029
MYSQL_ROW row= mysql_fetch_row(slave);
3030
if (row && row[9] && row[21])
3032
/* SHOW MASTER STATUS reports file and position */
3034
fprintf(md_result_file,
3035
"\n--\n-- Position to start replication or point-in-time "
3036
"recovery from (the master of this slave)\n--\n\n");
3038
fprintf(md_result_file, "%sCHANGE MASTER TO ", comment_prefix);
3040
if (opt_include_master_host_port)
3043
fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]);
3045
fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]);
3047
fprintf(md_result_file,
3048
"MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]);
3050
check_io(md_result_file);
3052
mysql_free_result(slave);
3057
static int do_start_slave_sql(MYSQL *mysql_con)
3060
/* We need to check if the slave sql is stopped in the first place */
3061
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
3065
MYSQL_ROW row= mysql_fetch_row(slave);
3068
/* if SLAVE SQL is not running, we don't start it */
3069
if (!strcmp(row[11],"Yes"))
3071
mysql_free_result(slave);
3072
/* Silently assume that they don't have the slave running */
3077
mysql_free_result(slave);
3079
/* now, start slave if stopped */
3080
if (mysql_query_with_error_report(mysql_con, 0, "START SLAVE"))
3082
my_printf_error(0, "Error: Unable to start slave", MYF(0));
3090
static int do_flush_tables_read_lock(MYSQL *mysql_con)
2512
3093
We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
2513
3094
will wait but will not stall the whole mysqld, and when the long update is
2514
3095
done the FLUSH TABLES WITH READ LOCK will start and succeed quickly. So,
2515
FLUSH TABLES is to lower the probability of a stage where both drizzled
3096
FLUSH TABLES is to lower the probability of a stage where both mysqldump
2516
3097
and most client connections are stalled. Of course, if a second long
2517
3098
update starts between the two FLUSHes, we have that bad stall.
2520
( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES", false) ||
2521
drizzleclient_query_with_error_report(drizzle_con, 0,
2522
"FLUSH TABLES WITH READ LOCK", false) );
2525
static int do_unlock_tables(drizzle_con_st *drizzle_con)
2527
return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES", false);
2530
static int start_transaction(drizzle_con_st *drizzle_con)
2532
return (drizzleclient_query_with_error_report(drizzle_con, 0,
2533
"SET SESSION TRANSACTION ISOLATION "
2534
"LEVEL REPEATABLE READ", false) ||
2535
drizzleclient_query_with_error_report(drizzle_con, 0,
2536
"START TRANSACTION "
2537
"WITH CONSISTENT SNAPSHOT", false));
2541
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
2542
char **err_pos, uint32_t *err_len)
3101
( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") ||
3102
mysql_query_with_error_report(mysql_con, 0,
3103
"FLUSH TABLES WITH READ LOCK") );
3107
static int do_unlock_tables(MYSQL *mysql_con)
3109
return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES");
3112
static int get_bin_log_name(MYSQL *mysql_con,
3113
char* buff_log_name, uint buff_len)
3118
if (mysql_query(mysql_con, "SHOW MASTER STATUS") ||
3119
!(res= mysql_store_result(mysql)))
3122
if (!(row= mysql_fetch_row(res)))
3124
mysql_free_result(res);
3128
Only one row is returned, and the first column is the name of the
3131
strmake(buff_log_name, row[0], buff_len - 1);
3133
mysql_free_result(res);
3137
static int purge_bin_logs_to(MYSQL *mysql_con, char* log_name)
3141
init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
3142
dynstr_append_checked(&str, log_name);
3143
dynstr_append_checked(&str, "'");
3144
err = mysql_query_with_error_report(mysql_con, 0, str.str);
3150
static int start_transaction(MYSQL *mysql_con)
3153
We use BEGIN for old servers. --single-transaction --master-data will fail
3154
on old servers, but that's ok as it was already silently broken (it didn't
3155
do a consistent read, so better tell people frankly, with the error).
3157
We want the first consistent read to be used for all tables to dump so we
3158
need the REPEATABLE READ level (not anything lower, for example READ
3159
COMMITTED would give one new consistent read per dumped table).
3161
if ((mysql_get_server_version(mysql_con) < 40100) && opt_master_data)
3163
fprintf(stderr, "-- %s: the combination of --single-transaction and "
3164
"--master-data requires a MySQL server version of at least 4.1 "
3165
"(current server's version is %s). %s\n",
3166
ignore_errors ? "Warning" : "Error",
3167
mysql_con->server_version ? mysql_con->server_version : "unknown",
3168
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3173
return (mysql_query_with_error_report(mysql_con, 0,
3174
"SET SESSION TRANSACTION ISOLATION "
3175
"LEVEL REPEATABLE READ") ||
3176
mysql_query_with_error_report(mysql_con, 0,
3177
"START TRANSACTION "
3178
"/*!40100 WITH CONSISTENT SNAPSHOT */"));
3182
static ulong find_set(TYPELIB *lib, const char *x, uint length,
3183
char **err_pos, uint *err_len)
2544
3185
const char *end= x + length;
2547
3188
char buff[255];
2549
3190
*err_pos= 0; /* No error yet */