80
80
char **err_pos, uint *err_len);
82
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,
83
static bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
84
84
quick= 1, extended_insert= 1,
85
85
lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
86
86
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
98
98
opt_include_master_host_port= 0,
100
100
opt_alltspcs=0, opt_notspcs= 0;
101
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
101
static bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
102
102
static ulong opt_max_allowed_packet, opt_net_buffer_length;
103
103
static MYSQL mysql_connection,*mysql=0;
104
104
static DYNAMIC_STRING insert_pat;
112
112
static char **defaults_argv= 0;
113
113
static char compatible_mode_normal_str[255];
114
114
/* Server supports character_set_results session variable? */
115
static my_bool server_supports_switching_charsets= TRUE;
115
static bool server_supports_switching_charsets= TRUE;
116
116
static ulong opt_compatible_mode= 0;
117
117
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
118
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
154
154
static CHARSET_INFO *charset_info= &my_charset_latin1;
155
155
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
156
156
/* have we seen any VIEWs during table scanning? */
157
my_bool seen_views= 0;
158
158
const char *compatible_mode_names[]=
160
160
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
237
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
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
240
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
248
241
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
249
242
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
487
480
static int init_dumping(char *, int init_func(char*));
488
481
static int dump_databases(char **);
489
482
static int dump_all_databases(void);
490
static char *quote_name(const char *name, char *buff, my_bool force);
483
static char *quote_name(const char *name, char *buff, bool force);
491
484
char check_if_ignore_table(const char *table_name, char *table_type);
492
485
static char *primary_key_fields(const char *table_name);
676
669
static uchar* get_table_key(const char *entry, size_t *length,
677
my_bool not_used __attribute__((unused)))
670
bool not_used __attribute__((unused)))
679
672
*length= strlen(entry);
680
673
return (uchar*) entry;
685
678
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
793
782
fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
796
#if !defined(DBUG_OFF)
798
uint size_for_sql_mode= 0;
800
for (ptr= compatible_mode_names; *ptr; ptr++)
801
size_for_sql_mode+= strlen(*ptr);
802
size_for_sql_mode+= sizeof(compatible_mode_names)-1;
803
DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode);
806
785
mode= opt_compatible_mode;
807
786
for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
934
913
static void DB_error(MYSQL *mysql_arg, const char *when)
936
DBUG_ENTER("DB_error");
937
916
maybe_die(EX_MYSQLERR, "Got error: %d: %s %s",
938
917
mysql_errno(mysql_arg), mysql_error(mysql_arg), when);
1122
1101
static int connect_to_db(char *host, char *user,char *passwd)
1124
1103
char buff[20+FN_REFLEN];
1125
DBUG_ENTER("connect_to_db");
1127
1106
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1128
1107
mysql_init(&mysql_connection);
1177
1156
static void unescape(FILE *file,char *pos,uint length)
1180
DBUG_ENTER("unescape");
1181
1160
if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1182
1161
die(EX_MYSQLERR, "Couldn't allocate memory");
1187
1166
fputc('\'', file);
1188
1167
check_io(file);
1189
1168
my_free(tmp, MYF(MY_WME));
1191
1170
} /* unescape */
1194
static my_bool test_if_special_chars(const char *str)
1173
static bool test_if_special_chars(const char *str)
1196
1175
#if MYSQL_VERSION_ID >= 32300
1197
1176
for ( ; *str ; str++)
1219
1198
buff quoted string
1222
static char *quote_name(const char *name, char *buff, my_bool force)
1201
static char *quote_name(const char *name, char *buff, bool force)
1224
1203
char *to= buff;
1225
1204
char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : '`';
1369
1348
while (attribute_name != NullS)
1371
1350
attribute_value= va_arg(arg_list, char *);
1372
DBUG_ASSERT(attribute_value != NullS);
1351
assert(attribute_value != NullS);
1374
1353
fputc(' ', xml_file);
1375
1354
fputs(attribute_name, xml_file);
1506
1485
static uint get_table_structure(char *table, char *db, char *table_type,
1507
1486
char *ignore_flag)
1509
my_bool init=0, delayed, write_data, complete_insert;
1488
bool init=0, delayed, write_data, complete_insert;
1510
1489
my_ulonglong num_fields;
1511
1490
char *result_table, *opt_quoted_table;
1512
1491
const char *insert_option;
1517
1496
MYSQL_RES *result;
1519
DBUG_ENTER("get_table_structure");
1520
DBUG_PRINT("enter", ("db: %s table: %s", db, table));
1522
1499
*ignore_flag= check_if_ignore_table(table, table_type);
1574
1551
if (switch_character_set_results(mysql, "binary") ||
1575
1552
mysql_query_with_error_report(mysql, &result, buff) ||
1576
1553
switch_character_set_results(mysql, default_charset))
1581
1558
if (!(sql_file= open_sql_file_for_table(table)))
1584
1561
write_header(sql_file, db);
1775
1752
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1777
1754
if (mysql_query_with_error_report(mysql, &result, query_buff))
1780
1757
/* Make an sql-file, if path was given iow. option -T was given */
1781
1758
if (!opt_no_create_info)
1883
1860
my_progname, result_table, mysql_error(mysql));
1885
1862
my_fclose(sql_file, MYF(MY_WME));
1889
1866
/* Find first which key is primary key */
2003
1980
write_footer(sql_file);
2004
1981
my_fclose(sql_file, MYF(MY_WME));
2006
DBUG_RETURN((uint) num_fields);
1983
return((uint) num_fields);
2007
1984
} /* get_table_structure */
2009
1986
static void add_load_option(DYNAMIC_STRING *str, const char *option,
2110
2087
The "table" could be a view. If so, we don't do anything here.
2112
2089
if (strcmp(table_type, "VIEW") == 0)
2115
2092
/* Check --no-data flag */
2116
2093
if (opt_no_data)
2118
2095
verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
2124
("ignore_flag: %x num_fields: %d", (int) ignore_flag,
2127
2101
If the table type is a merge table or any type that has to be
2128
2102
_completely_ ignored and no data dumped
2132
2106
verbose_msg("-- Warning: Skipping data for table '%s' because " \
2133
2107
"it's of type %s\n", table, table_type);
2136
2110
/* Check that there are any fields in the table */
2137
2111
if (num_fields == 0)
2139
2113
verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
2150
2124
!my_strcasecmp(&my_charset_latin1, table, "event"))
2152
2126
verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2156
2130
result_table= quote_name(table,table_buff, 1);
2369
2343
extended_row.length+= mysql_hex_string(extended_row.str +
2370
2344
extended_row.length,
2371
2345
row[i], length);
2372
DBUG_ASSERT(extended_row.length+1 <= extended_row.max_length);
2346
assert(extended_row.length+1 <= extended_row.max_length);
2373
2347
/* mysql_hex_string() already terminated string by '\0' */
2374
DBUG_ASSERT(extended_row.str[extended_row.length] == '\0');
2348
assert(extended_row.str[extended_row.length] == '\0');
2711
2685
/* Return 1 if we should copy the table */
2713
static my_bool include_table(const uchar *hash_key, size_t len)
2687
static bool include_table(const uchar *hash_key, size_t len)
2715
2689
return !hash_search(&ignore_table, hash_key, len);
2724
2698
char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
2725
2699
char *afterdot;
2726
2700
int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
2727
DBUG_ENTER("dump_all_tables_in_db");
2729
2703
afterdot= strmov(hash_key, database);
2730
2704
*afterdot++= '.';
2732
2706
if (init_dumping(database, init_dumping_tables))
2735
2709
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2736
2710
if (lock_tables)
2803
2777
char query[50 + 2*NAME_LEN];
2804
2778
char show_name_buff[FN_REFLEN];
2805
DBUG_ENTER("get_actual_table_name");
2807
2781
/* Check memory for quote_for_like() */
2808
DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff));
2782
assert(2*sizeof(old_table_name) < sizeof(show_name_buff));
2809
2783
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2810
2784
quote_for_like(old_table_name, show_name_buff));
2839
2812
DYNAMIC_STRING lock_tables_query;
2841
2814
char **dump_tables, **pos, **end;
2842
DBUG_ENTER("dump_selected_tables");
2844
2817
if (init_dumping(db, init_dumping_tables))
2847
2820
init_alloc_root(&root, 8192, 0);
2848
2821
if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2906
2879
/* Dump each selected table */
2907
2880
for (pos= dump_tables; pos < end; pos++)
2909
DBUG_PRINT("info",("Dumping table %s", *pos));
2910
2881
dump_table(*pos, db);
2913
2883
free_root(&root, MYF(0));
2914
2884
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
3279
3249
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3280
3250
MYSQL_RES *res= NULL;
3282
DBUG_ENTER("check_if_ignore_table");
3284
3254
/* Check memory for quote_for_like() */
3285
DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff));
3255
assert(2*sizeof(table_name) < sizeof(show_name_buff));
3286
3256
snprintf(buff, sizeof(buff), "show table status like %s",
3287
3257
quote_for_like(table_name, show_name_buff));
3288
3258
if (mysql_query_with_error_report(mysql, &res, buff))
3291
3261
{ /* If old MySQL version */
3292
3262
verbose_msg("-- Warning: Couldn't get status information for "
3293
3263
"table %s (%s)\n", table_name, mysql_error(mysql));
3294
DBUG_RETURN(result); /* assume table is ok */
3264
return(result); /* assume table is ok */
3297
3267
if (!(row= mysql_fetch_row(res)))
3300
3270
"Error: Couldn't read status information for table %s (%s)\n",
3301
3271
table_name, mysql_error(mysql));
3302
3272
mysql_free_result(res);
3303
DBUG_RETURN(result); /* assume table is ok */
3273
return(result); /* assume table is ok */
3306
3276
strmake(table_type, "VIEW", NAME_LEN-1);