mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
New option to mysqldump.
Docs/manual.texi: New option, -r, to mysqldump. This is needed in MSDOS mode. client/mysqldump.c: Added option -r for MSDOS mode.
This commit is contained in:
@ -32515,6 +32515,10 @@ used.)
|
|||||||
@item -q, --quick
|
@item -q, --quick
|
||||||
Don't buffer query, dump directly to stdout. Uses @code{mysql_use_result()}
|
Don't buffer query, dump directly to stdout. Uses @code{mysql_use_result()}
|
||||||
to do this.
|
to do this.
|
||||||
|
@item -r, --result-file=...
|
||||||
|
Direct output to a given file. This option should be used in MSDOS,
|
||||||
|
because it prevents new line '\n' from being converted to '\n\r' (new
|
||||||
|
line + carriage return).
|
||||||
@item -S /path/to/socket, --socket=/path/to/socket
|
@item -S /path/to/socket, --socket=/path/to/socket
|
||||||
The socket file to use when connecting to @code{localhost} (which is the
|
The socket file to use when connecting to @code{localhost} (which is the
|
||||||
default host).
|
default host).
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
** T<>nu Samuel <tonu@please.do.not.remove.this.spam.ee>
|
** T<>nu Samuel <tonu@please.do.not.remove.this.spam.ee>
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#define DUMP_VERSION "8.13"
|
#define DUMP_VERSION "8.14"
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <my_sys.h>
|
#include <my_sys.h>
|
||||||
@ -73,7 +73,8 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick=0, extended_insert = 0,
|
|||||||
lock_tables=0,ignore_errors=0,flush_logs=0,replace=0,
|
lock_tables=0,ignore_errors=0,flush_logs=0,replace=0,
|
||||||
ignore=0,opt_drop=0,opt_keywords=0,opt_lock=0,opt_compress=0,
|
ignore=0,opt_drop=0,opt_keywords=0,opt_lock=0,opt_compress=0,
|
||||||
opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0,
|
opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0,
|
||||||
opt_alldbs=0,opt_create_db=0,opt_first_slave=0;
|
opt_alldbs=0,opt_create_db=0,opt_first_slave=0,
|
||||||
|
opt_resultfile=0;
|
||||||
static MYSQL mysql_connection,*sock=0;
|
static MYSQL mysql_connection,*sock=0;
|
||||||
static char insert_pat[12 * 1024],*opt_password=0,*current_user=0,
|
static char insert_pat[12 * 1024],*opt_password=0,*current_user=0,
|
||||||
*current_host=0,*path=0,*fields_terminated=0,
|
*current_host=0,*path=0,*fields_terminated=0,
|
||||||
@ -127,6 +128,7 @@ static struct option long_options[] =
|
|||||||
{"port", required_argument, 0, 'P'},
|
{"port", required_argument, 0, 'P'},
|
||||||
{"quick", no_argument, 0, 'q'},
|
{"quick", no_argument, 0, 'q'},
|
||||||
{"quote-names", no_argument, 0, 'Q'},
|
{"quote-names", no_argument, 0, 'Q'},
|
||||||
|
{"result-file", required_argument, 0, 'r'},
|
||||||
{"set-variable", required_argument, 0, 'O'},
|
{"set-variable", required_argument, 0, 'O'},
|
||||||
{"socket", required_argument, 0, 'S'},
|
{"socket", required_argument, 0, 'S'},
|
||||||
#include "sslopt-longopts.h"
|
#include "sslopt-longopts.h"
|
||||||
@ -227,6 +229,10 @@ puts("\
|
|||||||
-P, --port=... Port number to use for connection.\n\
|
-P, --port=... Port number to use for connection.\n\
|
||||||
-q, --quick Don't buffer query, dump directly to stdout.\n\
|
-q, --quick Don't buffer query, dump directly to stdout.\n\
|
||||||
-Q, --quote-names Quote table and column names with `\n\
|
-Q, --quote-names Quote table and column names with `\n\
|
||||||
|
-r, --result-file=... Direct output to a given file. This option should be\n\
|
||||||
|
used in MSDOS, because it prevents new line '\\n'\n\
|
||||||
|
from being converted to '\\n\\r' (newline + carriage\n\
|
||||||
|
return).\n\
|
||||||
-S, --socket=... Socket file to use for connection.\n\
|
-S, --socket=... Socket file to use for connection.\n\
|
||||||
--tables Overrides option --databases (-B).\n");
|
--tables Overrides option --databases (-B).\n");
|
||||||
#include "sslopt-usage.h"
|
#include "sslopt-usage.h"
|
||||||
@ -283,10 +289,12 @@ static int get_options(int *argc,char ***argv)
|
|||||||
{
|
{
|
||||||
int c,option_index;
|
int c,option_index;
|
||||||
my_bool tty_password=0;
|
my_bool tty_password=0;
|
||||||
|
FILE *resultfile;
|
||||||
|
|
||||||
load_defaults("my",load_default_groups,argc,argv);
|
load_defaults("my",load_default_groups,argc,argv);
|
||||||
set_all_changeable_vars(changeable_vars);
|
set_all_changeable_vars(changeable_vars);
|
||||||
while ((c=getopt_long(*argc,*argv,"#::p::h:u:O:P:S:T:EBaAcCdefFlnqtvVw:?Ix",
|
while ((c=getopt_long(*argc,*argv,
|
||||||
|
"#::p::h:u:O:P:r:S:T:EBaAcCdefFlnqtvVw:?Ix",
|
||||||
long_options, &option_index)) != EOF)
|
long_options, &option_index)) != EOF)
|
||||||
{
|
{
|
||||||
switch(c) {
|
switch(c) {
|
||||||
@ -346,6 +354,15 @@ static int get_options(int *argc,char ***argv)
|
|||||||
case 'P':
|
case 'P':
|
||||||
opt_mysql_port= (unsigned int) atoi(optarg);
|
opt_mysql_port= (unsigned int) atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
if (!(resultfile = my_fopen(optarg, O_WRONLY, MYF(MY_WME))))
|
||||||
|
{
|
||||||
|
printf("Couldn't open result-file %s, aborting!\n", optarg);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
opt_resultfile = 1;
|
||||||
|
stdout = resultfile;
|
||||||
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
opt_mysql_unix_port= optarg;
|
opt_mysql_unix_port= optarg;
|
||||||
break;
|
break;
|
||||||
@ -625,8 +642,8 @@ static uint getTableStructure(char *table, char* db)
|
|||||||
O_WRONLY, MYF(MY_WME));
|
O_WRONLY, MYF(MY_WME));
|
||||||
if (!sql_file) /* If file couldn't be opened */
|
if (!sql_file) /* If file couldn't be opened */
|
||||||
{
|
{
|
||||||
safe_exit(EX_MYSQLERR);
|
safe_exit(EX_MYSQLERR);
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
}
|
}
|
||||||
write_heder(sql_file, db);
|
write_heder(sql_file, db);
|
||||||
}
|
}
|
||||||
@ -734,20 +751,20 @@ static uint getTableStructure(char *table, char* db)
|
|||||||
if (!tFlag)
|
if (!tFlag)
|
||||||
{
|
{
|
||||||
if (opt_keywords)
|
if (opt_keywords)
|
||||||
fprintf(sql_file, " %s.%s %s", table_name,
|
fprintf(sql_file, " %s.%s %s", table_name,
|
||||||
quote_name(row[SHOW_FIELDNAME],name_buff), row[SHOW_TYPE]);
|
quote_name(row[SHOW_FIELDNAME],name_buff), row[SHOW_TYPE]);
|
||||||
else
|
else
|
||||||
fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME],name_buff),
|
fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME],
|
||||||
row[SHOW_TYPE]);
|
name_buff), row[SHOW_TYPE]);
|
||||||
if (row[SHOW_DEFAULT])
|
if (row[SHOW_DEFAULT])
|
||||||
{
|
{
|
||||||
fputs(" DEFAULT ", sql_file);
|
fputs(" DEFAULT ", sql_file);
|
||||||
unescape(sql_file,row[SHOW_DEFAULT],lengths[SHOW_DEFAULT]);
|
unescape(sql_file,row[SHOW_DEFAULT],lengths[SHOW_DEFAULT]);
|
||||||
}
|
}
|
||||||
if (!row[SHOW_NULL][0])
|
if (!row[SHOW_NULL][0])
|
||||||
fputs(" NOT NULL", sql_file);
|
fputs(" NOT NULL", sql_file);
|
||||||
if (row[SHOW_EXTRA][0])
|
if (row[SHOW_EXTRA][0])
|
||||||
fprintf(sql_file, " %s",row[SHOW_EXTRA]);
|
fprintf(sql_file, " %s",row[SHOW_EXTRA]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
numFields = (uint) mysql_num_rows(tableRes);
|
numFields = (uint) mysql_num_rows(tableRes);
|
||||||
@ -761,9 +778,9 @@ static uint getTableStructure(char *table, char* db)
|
|||||||
if (mysql_query(sock, buff))
|
if (mysql_query(sock, buff))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: Can't get keys for table '%s' (%s)\n",
|
fprintf(stderr, "%s: Can't get keys for table '%s' (%s)\n",
|
||||||
my_progname, table, mysql_error(sock));
|
my_progname, table, mysql_error(sock));
|
||||||
if (sql_file != stdout)
|
if (sql_file != stdout)
|
||||||
my_fclose(sql_file, MYF(MY_WME));
|
my_fclose(sql_file, MYF(MY_WME));
|
||||||
safe_exit(EX_MYSQLERR);
|
safe_exit(EX_MYSQLERR);
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
}
|
}
|
||||||
@ -776,16 +793,16 @@ static uint getTableStructure(char *table, char* db)
|
|||||||
{
|
{
|
||||||
if (atoi(row[3]) == 1)
|
if (atoi(row[3]) == 1)
|
||||||
{
|
{
|
||||||
keynr++;
|
keynr++;
|
||||||
#ifdef FORCE_PRIMARY_KEY
|
#ifdef FORCE_PRIMARY_KEY
|
||||||
if (atoi(row[1]) == 0 && primary_key == INT_MAX)
|
if (atoi(row[1]) == 0 && primary_key == INT_MAX)
|
||||||
primary_key=keynr;
|
primary_key=keynr;
|
||||||
#endif
|
#endif
|
||||||
if (!strcmp(row[2],"PRIMARY"))
|
if (!strcmp(row[2],"PRIMARY"))
|
||||||
{
|
{
|
||||||
primary_key=keynr;
|
primary_key=keynr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mysql_data_seek(tableRes,0);
|
mysql_data_seek(tableRes,0);
|
||||||
@ -794,21 +811,21 @@ static uint getTableStructure(char *table, char* db)
|
|||||||
{
|
{
|
||||||
if (atoi(row[3]) == 1)
|
if (atoi(row[3]) == 1)
|
||||||
{
|
{
|
||||||
if (keynr++)
|
if (keynr++)
|
||||||
putc(')', sql_file);
|
putc(')', sql_file);
|
||||||
if (atoi(row[1])) /* Test if duplicate key */
|
if (atoi(row[1])) /* Test if duplicate key */
|
||||||
/* Duplicate allowed */
|
/* Duplicate allowed */
|
||||||
fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff));
|
fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff));
|
||||||
else if (keynr == primary_key)
|
else if (keynr == primary_key)
|
||||||
fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */
|
fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */
|
||||||
else
|
else
|
||||||
fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff));
|
fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
putc(',', sql_file);
|
putc(',', sql_file);
|
||||||
fputs(quote_name(row[4],name_buff), sql_file);
|
fputs(quote_name(row[4],name_buff), sql_file);
|
||||||
if (row[7])
|
if (row[7])
|
||||||
fprintf(sql_file, " (%s)",row[7]); /* Sub key */
|
fprintf(sql_file, " (%s)",row[7]); /* Sub key */
|
||||||
}
|
}
|
||||||
if (keynr)
|
if (keynr)
|
||||||
putc(')', sql_file);
|
putc(')', sql_file);
|
||||||
@ -820,28 +837,28 @@ static uint getTableStructure(char *table, char* db)
|
|||||||
sprintf(buff,"show table status like '%s'",table);
|
sprintf(buff,"show table status like '%s'",table);
|
||||||
if (mysql_query(sock, buff))
|
if (mysql_query(sock, buff))
|
||||||
{
|
{
|
||||||
if (mysql_errno(sock) != ER_PARSE_ERROR)
|
if (mysql_errno(sock) != ER_PARSE_ERROR)
|
||||||
{ /* If old MySQL version */
|
{ /* If old MySQL version */
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"# Warning: Couldn't get status information for table '%s' (%s)\n",
|
"# Warning: Couldn't get status information for table '%s' (%s)\n",
|
||||||
table,mysql_error(sock));
|
table,mysql_error(sock));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!(tableRes=mysql_store_result(sock)) ||
|
else if (!(tableRes=mysql_store_result(sock)) ||
|
||||||
!(row=mysql_fetch_row(tableRes)))
|
!(row=mysql_fetch_row(tableRes)))
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: Couldn't read status information for table '%s' (%s)\n",
|
"Error: Couldn't read status information for table '%s' (%s)\n",
|
||||||
table,mysql_error(sock));
|
table,mysql_error(sock));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fputs("/*!",sql_file);
|
fputs("/*!",sql_file);
|
||||||
print_value(sql_file,tableRes,row,"type=","Type",0);
|
print_value(sql_file,tableRes,row,"type=","Type",0);
|
||||||
print_value(sql_file,tableRes,row,"","Create_options",0);
|
print_value(sql_file,tableRes,row,"","Create_options",0);
|
||||||
print_value(sql_file,tableRes,row,"comment=","Comment",1);
|
print_value(sql_file,tableRes,row,"comment=","Comment",1);
|
||||||
fputs(" */",sql_file);
|
fputs(" */",sql_file);
|
||||||
}
|
}
|
||||||
mysql_free_result(tableRes); /* Is always safe to free */
|
mysql_free_result(tableRes); /* Is always safe to free */
|
||||||
}
|
}
|
||||||
@ -967,7 +984,7 @@ static void dumpTable(uint numFields, char *table)
|
|||||||
printf("# WHERE: %s\n",where);
|
printf("# WHERE: %s\n",where);
|
||||||
strxmov(strend(query), " WHERE ",where,NullS);
|
strxmov(strend(query), " WHERE ",where,NullS);
|
||||||
}
|
}
|
||||||
puts("#\n");
|
fputs("#\n\n", stdout);
|
||||||
|
|
||||||
if (mysql_query(sock, query))
|
if (mysql_query(sock, query))
|
||||||
{
|
{
|
||||||
@ -1090,7 +1107,7 @@ static void dumpTable(uint numFields, char *table)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (row_break)
|
if (row_break)
|
||||||
puts(";");
|
fputs(";\n", stdout);
|
||||||
row_break=1; /* This is first row */
|
row_break=1; /* This is first row */
|
||||||
fputs(insert_pat,stdout);
|
fputs(insert_pat,stdout);
|
||||||
fputs(extended_row.str,stdout);
|
fputs(extended_row.str,stdout);
|
||||||
@ -1098,12 +1115,10 @@ static void dumpTable(uint numFields, char *table)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
fputs(");\n", stdout);
|
||||||
puts(");");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (extended_insert && row_break)
|
if (extended_insert && row_break)
|
||||||
puts(";"); /* If not empty table */
|
fputs(";\n", stdout); /* If not empty table */
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (mysql_errno(sock))
|
if (mysql_errno(sock))
|
||||||
{
|
{
|
||||||
@ -1118,7 +1133,7 @@ static void dumpTable(uint numFields, char *table)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (opt_lock)
|
if (opt_lock)
|
||||||
puts("UNLOCK TABLES;");
|
fputs("UNLOCK TABLES;\n", stdout);
|
||||||
mysql_free_result(res);
|
mysql_free_result(res);
|
||||||
}
|
}
|
||||||
} /* dumpTable */
|
} /* dumpTable */
|
||||||
@ -1365,7 +1380,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbDisconnect(current_host);
|
dbDisconnect(current_host);
|
||||||
puts("");
|
fputs("\n", stdout);
|
||||||
|
if (opt_resultfile)
|
||||||
|
my_fclose(stdout, MYF(0));
|
||||||
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
|
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
|
||||||
if (extended_insert)
|
if (extended_insert)
|
||||||
dynstr_free(&extended_row);
|
dynstr_free(&extended_row);
|
||||||
|
Reference in New Issue
Block a user