<commit_before>/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/* mysqldump.c  - Dump a tables contents and format to an ASCII file
**
** The author's original notes follow :-
**
** AUTHOR: <NAME> (<EMAIL>)
** DATE:   December 3, 1994
** WARRANTY: None, expressed, impressed, implied
**	    or other
** STATUS: Public domain
** Adapted and optimized for MySQL by
** <NAME>, <NAME>, <NAME>
** -w --where added 9/10/98 by <NAME>
** slave code by <NAME> <<EMAIL>>
** master/autocommit code by <NAME> <<EMAIL>>
** SSL by
** <NAME> <<EMAIL>>
** <NAME>  <<EMAIL>>
** XML by <NAME> <<EMAIL>> 10/10/01, cleaned up
** and adapted to mysqldump 05/11/01 by <NAME>
*/

#define DUMP_VERSION "8.21"

#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <m_ctype.h>

#include "client_priv.h"
#include "mysql.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include <getopt.h>

/* Exit codes */

#define EX_USAGE 1
#define EX_MYSQLERR 2
#define EX_CONSCHECK 3
#define EX_EOM 4

/* index into 'show fields from table' */

#define SHOW_FIELDNAME  0
#define SHOW_TYPE  1
#define SHOW_NULL  2
#define SHOW_DEFAULT  4
#define SHOW_EXTRA  5
#define QUOTE_CHAR	'`'

static char *add_load_option(char *ptr, const char *object,
			     const char *statement);

static char *field_escape(char *to,const char *from,uint length);
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,
		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_alldbs=0,opt_create_db=0,opt_first_slave=0,
                opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0;
static MYSQL  mysql_connection,*sock=0;
static char  insert_pat[12 * 1024],*opt_password=0,*current_user=0,
             *current_host=0,*path=0,*fields_terminated=0,
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
             *where=0, *default_charset;
static uint     opt_mysql_port=0;
static my_string opt_mysql_unix_port=0;
static int   first_error=0;
extern ulong net_buffer_length;
static DYNAMIC_STRING extended_row;
#include "sslopt-vars.h"
FILE  *md_result_file;

static struct option long_options[] =
{
  {"all-databases",     no_argument,    0,      'A'},
  {"all",		no_argument,    0,	'a'},
  {"add-drop-table",	no_argument,    0,	OPT_DROP},
  {"add-locks",         no_argument,    0,	OPT_LOCKS},
  {"allow-keywords",	no_argument,    0,	OPT_KEYWORDS},
  {"character-sets-dir",required_argument,0,    OPT_CHARSETS_DIR},
  {"complete-insert",	no_argument,    0,	'c'},
  {"compress",          no_argument,    0,	'C'},
  {"databases",         no_argument,    0,      'B'},
  {"debug",		optional_argument,	0, '#'},
  {"default-character-set", required_argument,  0, OPT_DEFAULT_CHARSET},
  {"delayed-insert",	no_argument,    0,	OPT_DELAYED},
  {"disable-keys",	no_argument,    0,	'K'},
  {"extended-insert",   no_argument,    0,	'e'},
  {"fields-terminated-by", required_argument,   0, (int) OPT_FTB},
  {"fields-enclosed-by", required_argument,	0, (int) OPT_ENC},
  {"fields-optionally-enclosed-by", required_argument, 0, (int) OPT_O_ENC},
  {"fields-escaped-by", required_argument,	0, (int) OPT_ESC},
  {"first-slave",	no_argument,    0,	'x'},
  {"flush-logs",	no_argument,    0,	'F'},
  {"force",		no_argument,    0,	'f'},
  {"help",		no_argument,    0,	'?'},
  {"host",		required_argument,	0, 'h'},
  {"lines-terminated-by", required_argument,    0, (int) OPT_LTB},
  {"lock-tables",       no_argument,    0,	'l'},
  {"master-data",	no_argument,    0,	OPT_MASTER_DATA},
  {"no-autocommit",     no_argument,    0,      OPT_AUTOCOMMIT},
  {"no-create-db",      no_argument,    0,      'n'},
  {"no-create-info",	no_argument,    0,	't'},
  {"no-data",		no_argument,    0,	'd'},
  {"opt",		no_argument,    0,	OPT_OPTIMIZE},
  {"password",          optional_argument,	0, 'p'},
#ifdef __WIN__
  {"pipe",		no_argument,		0, 'W'},
#endif
  {"port",		required_argument,	0, 'P'},
  {"quick",		no_argument,		0, 'q'},
  {"quote-names",	no_argument,		0, 'Q'},
  {"result-file",       required_argument,      0, 'r'},
  {"set-variable",	required_argument,	0, 'O'},
  {"socket",		required_argument,	0, 'S'},
#include "sslopt-longopts.h"
  {"tab",		required_argument,	0, 'T'},
  {"tables",            no_argument,            0, OPT_TABLES},
#ifndef DONT_ALLOW_USER_CHANGE
  {"user",		required_argument,	0, 'u'},
#endif
  {"verbose",	        no_argument,		0, 'v'},
  {"version",	        no_argument,	        0, 'V'},
  {"where",		required_argument,	0, 'w'},
  {"xml",		no_argument,		0, 'X'},
  {0, 0, 0, 0}
};

static const char *load_default_groups[]= { "mysqldump","client",0 };

CHANGEABLE_VAR md_changeable_vars[] = {
  { "max_allowed_packet", (long*) &max_allowed_packet,24*1024*1024,4096,
    24*1024L*1024L,MALLOC_OVERHEAD,1024},
  { "net_buffer_length", (long*) &net_buffer_length,1024*1024L-1025,4096,
    24*1024L*1024L,MALLOC_OVERHEAD,1024},
  { 0, 0, 0, 0, 0, 0, 0}
};

static void safe_exit(int error);
static void write_header(FILE *sql_file, char *db_name);
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
			const char *prefix,const char *name,
			int string_value);
static int dump_selected_tables(char *db, char **table_names, int tables);
static int dump_all_tables_in_db(char *db);<commit_msg>Decrease net_buffer_length to not get problems when running against mysqld with same max_allowed_packet<commit_after>/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/* mysqldump.c  - Dump a tables contents and format to an ASCII file
**
** The author's original notes follow :-
**
** AUTHOR: <NAME> (<EMAIL>)
** DATE:   December 3, 1994
** WARRANTY: None, expressed, impressed, implied
**	    or other
** STATUS: Public domain
** Adapted and optimized for MySQL by
** <NAME>, <NAME>, <NAME>
** -w --where added 9/10/98 by <NAME>
** slave code by <NAME> <<EMAIL>>
** master/autocommit code by <NAME> <<EMAIL>>
** SSL by
** <NAME> <<EMAIL>>
** <NAME>  <<EMAIL>>
** XML by <NAME> <<EMAIL>> 10/10/01, cleaned up
** and adapted to mysqldump 05/11/01 by <NAME>
*/

#define DUMP_VERSION "8.21"

#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <m_ctype.h>

#include "client_priv.h"
#include "mysql.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include <getopt.h>

/* Exit codes */

#define EX_USAGE 1
#define EX_MYSQLERR 2
#define EX_CONSCHECK 3
#define EX_EOM 4

/* index into 'show fields from table' */

#define SHOW_FIELDNAME  0
#define SHOW_TYPE  1
#define SHOW_NULL  2
#define SHOW_DEFAULT  4
#define SHOW_EXTRA  5
#define QUOTE_CHAR	'`'

static char *add_load_option(char *ptr, const char *object,
			     const char *statement);

static char *field_escape(char *to,const char *from,uint length);
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,
		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_alldbs=0,opt_create_db=0,opt_first_slave=0,
                opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0;
static MYSQL  mysql_connection,*sock=0;
static char  insert_pat[12 * 1024],*opt_password=0,*current_user=0,
             *current_host=0,*path=0,*fields_terminated=0,
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
             *where=0, *default_charset;
static uint     opt_mysql_port=0;
static my_string opt_mysql_unix_port=0;
static int   first_error=0;
extern ulong net_buffer_length;
static DYNAMIC_STRING extended_row;
#include "sslopt-vars.h"
FILE  *md_result_file;

static struct option long_options[] =
{
  {"all-databases",     no_argument,    0,      'A'},
  {"all",		no_argument,    0,	'a'},
  {"add-drop-table",	no_argument,    0,	OPT_DROP},
  {"add-locks",         no_argument,    0,	OPT_LOCKS},
  {"allow-keywords",	no_argument,    0,	OPT_KEYWORDS},
  {"character-sets-dir",required_argument,0,    OPT_CHARSETS_DIR},
  {"complete-insert",	no_argument,    0,	'c'},
  {"compress",          no_argument,    0,	'C'},
  {"databases",         no_argument,    0,      'B'},
  {"debug",		optional_argument,	0, '#'},
  {"default-character-set", required_argument,  0, OPT_DEFAULT_CHARSET},
  {"delayed-insert",	no_argument,    0,	OPT_DELAYED},
  {"disable-keys",	no_argument,    0,	'K'},
  {"extended-insert",   no_argument,    0,	'e'},
  {"fields-terminated-by", required_argument,   0, (int) OPT_FTB},
  {"fields-enclosed-by", required_argument,	0, (int) OPT_ENC},
  {"fields-optionally-enclosed-by", required_argument, 0, (int) OPT_O_ENC},
  {"fields-escaped-by", required_argument,	0, (int) OPT_ESC},
  {"first-slave",	no_argument,    0,	'x'},
  {"flush-logs",	no_argument,    0,	'F'},
  {"force",		no_argument,    0,	'f'},
  {"help",		no_argument,    0,	'?'},
  {"host",		required_argument,	0, 'h'},
  {"lines-terminated-by", required_argument,    0, (int) OPT_LTB},
  {"lock-tables",       no_argument,    0,	'l'},
  {"master-data",	no_argument,    0,	OPT_MASTER_DATA},
  {"no-autocommit",     no_argument,    0,      OPT_AUTOCOMMIT},
  {"no-create-db",      no_argument,    0,      'n'},
  {"no-create-info",	no_argument,    0,	't'},
  {"no-data",		no_argument,    0,	'd'},
  {"opt",		no_argument,    0,	OPT_OPTIMIZE},
  {"password",          optional_argument,	0, 'p'},
#ifdef __WIN__
  {"pipe",		no_argument,		0, 'W'},
#endif
  {"port",		required_argument,	0, 'P'},
  {"quick",		no_argument,		0, 'q'},
  {"quote-names",	no_argument,		0, 'Q'},
  {"result-file",       required_argument,      0, 'r'},
  {"set-variable",	required_argument,	0, 'O'},
  {"socket",		required_argument,	0, 'S'},
#include "sslopt-longopts.h"
  {"tab",		required_argument,	0, 'T'},
  {"tables",            no_argument,            0, OPT_TABLES},
#ifndef DONT_ALLOW_USER_CHANGE
  {"user",		required_argument,	0, 'u'},
#endif
  {"verbose",	        no_argument,		0, 'v'},
  {"version",	        no_argument,	        0, 'V'},
  {"where",		required_argument,	0, 'w'},
  {"xml",		no_argument,		0, 'X'},
  {0, 0, 0, 0}
};

static const char *load_default_groups[]= { "mysqldump","client",0 };

CHANGEABLE_VAR md_changeable_vars[] = {
  { "max_allowed_packet", (long*) &max_allowed_packet,24*1024*1024,4096,
    24*1024L*1024L,MALLOC_OVERHEAD,1024},
  { "net_buffer_length", (long*) &net_buffer_length,1024*1024L-1025,4096,
    24*1024L*1024L,MALLOC_OVERHEAD-1024,1024},
  { 0, 0, 0, 0, 0, 0, 0}
};

static void safe_exit(int error);
static void write_header(FILE *sql_file, char *db_name);
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
			const char *prefix,const char *name,
			int string_value);
static int dump_selected_tables(char *db, char **table_names, int tables);
static int dump_all_tables_in_db(char *db);
{'fraction_non_alphanumeric': 0.15038633590890607, 'fraction_numerical': 0.03513623424156161, 'mean_word_length': 4.068425391591097, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1829569', 'n_tokens_mistral': 4786, 'n_tokens_neox': 4523, 'n_words': 1161}