summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/mysqlbinlog.cc27
-rw-r--r--client/mysqldump.c36
2 files changed, 45 insertions, 18 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 68b7da78bbf..f870c92cb6d 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -52,7 +52,7 @@ static const char* host = 0;
static int port = MYSQL_PORT;
static const char* sock= 0;
static const char* user = 0;
-static const char* pass = "";
+static char* pass = 0;
static ulonglong position = 0;
static short binlog_flags = 0;
static MYSQL* mysql = NULL;
@@ -226,7 +226,7 @@ static struct my_option my_long_options[] =
{"offset", 'o', "Skip the first N entries.", (gptr*) &offset, (gptr*) &offset,
0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p', "Password to connect to remote server.",
- 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Use port to connect to the remote server.",
(gptr*) &port, (gptr*) &port, 0, GET_INT, REQUIRED_ARG, MYSQL_PORT, 0, 0,
0, 0, 0},
@@ -266,6 +266,11 @@ void sql_print_error(const char *format,...)
va_end(args);
}
+static void cleanup()
+{
+ my_free(pass,MYF(MY_ALLOW_ZERO_PTR));
+}
+
static void die(const char* fmt, ...)
{
va_list args;
@@ -274,6 +279,7 @@ static void die(const char* fmt, ...)
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
+ cleanup();
exit(1);
}
@@ -333,6 +339,7 @@ extern "C" my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
+ bool tty_password=0;
switch (optid) {
#ifndef DBUG_OFF
case '#':
@@ -343,7 +350,17 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
one_database = 1;
break;
case 'p':
- pass = my_strdup(argument, MYF(0));
+ if (argument)
+ {
+ my_free(pass,MYF(MY_ALLOW_ZERO_PTR));
+ char *start=argument;
+ pass= my_strdup(argument,MYF(MY_FAE));
+ while (*argument) *argument++= 'x'; /* Destroy argument */
+ if (*start)
+ start[1]=0; /* Cut length of argument */
+ }
+ else
+ tty_password=1;
break;
case 'r':
if (!(result_file = my_fopen(argument, O_WRONLY | O_BINARY, MYF(MY_WME))))
@@ -359,6 +376,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
usage();
exit(0);
}
+ if (tty_password)
+ pass= get_tty_password(NullS);
+
return 0;
}
@@ -707,6 +727,7 @@ int main(int argc, char** argv)
my_fclose(result_file, MYF(0));
if (remote_opt)
mysql_close(mysql);
+ cleanup();
free_defaults(defaults_argv);
my_end(0);
return 0;
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 5e83e7bd043..31305c93e6c 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -632,6 +632,7 @@ static my_bool test_if_special_chars(const char *str)
} /* test_if_special_chars */
+
static char *quote_name(const char *name, char *buff, my_bool force)
{
char *to= buff;
@@ -789,7 +790,8 @@ static uint getTableStructure(char *table, char* db)
if (verbose)
fprintf(stderr, "-- Retrieving table structure for table %s...\n", table);
- sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", (opt_quoted || opt_keywords));
+ sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
+ (opt_quoted || opt_keywords));
result_table= quote_name(table, table_buff, 1);
opt_quoted_table= quote_name(table, table_buff2, 0);
if (!opt_xml && !mysql_query(sock,insert_pat))
@@ -1041,7 +1043,8 @@ static uint getTableStructure(char *table, char* db)
else if (keynr == primary_key)
fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */
else
- fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff,0));
+ fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff,
+ 0));
}
else
putc(',', sql_file);
@@ -1520,23 +1523,28 @@ static int init_dumping(char *database)
{
if (opt_databases || opt_alldbs)
{
- fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", database);
+ /*
+ length of table name * 2 (if name contain quotas), 2 quotas and 0
+ */
+ char quoted_database_buf[64*2+3];
+ char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
+
+ fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase);
if (!opt_create_db)
{
- char qbuf[128];
+ char qbuf[256];
MYSQL_ROW row;
MYSQL_RES *dbinfo;
- sprintf(qbuf,"SHOW CREATE DATABASE WITH IF NOT EXISTS %s",database);
+ sprintf(qbuf,"SHOW CREATE DATABASE WITH IF NOT EXISTS %s",
+ qdatabase);
if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock)))
{
/* Old server version, dump generic CREATE DATABASE */
fprintf(md_result_file,
- "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s%s%s;\n",
- (opt_quoted ? "`" : ""),
- database,
- (opt_quoted ? "`" : ""));
+ "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
+ qdatabase);
}
else
{
@@ -1547,18 +1555,16 @@ static int init_dumping(char *database)
}
}
}
- fprintf(md_result_file,"\nUSE %s%s%s;\n", (opt_quoted ? "`" : ""),
- database,
- (opt_quoted ? "`" : ""));
+ fprintf(md_result_file,"\nUSE %s;\n", qdatabase);
}
}
- if (extended_insert)
- if (init_dynamic_string(&extended_row, "", 1024, 1024))
- exit(EX_EOM);
+ if (extended_insert && init_dynamic_string(&extended_row, "", 1024, 1024))
+ exit(EX_EOM);
return 0;
} /* init_dumping */
+
static int dump_all_tables_in_db(char *database)
{
char *table;