MySQL 8.4.3
Source Code Documentation
mysqldump.cc File Reference
#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string>
#include <unordered_map>
#include "client/include/client_priv.h"
#include "client/multi_option.h"
#include "compression.h"
#include "m_string.h"
#include "map_helpers.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h"
#include "my_hostname.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_sys.h"
#include "my_systime.h"
#include "my_user.h"
#include "mysql.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include "nulls.h"
#include "prealloced_array.h"
#include "print_version.h"
#include "scope_guard.h"
#include "string_with_len.h"
#include "strmake.h"
#include "strxmov.h"
#include "template_utils.h"
#include "typelib.h"
#include "welcome_copyright_notice.h"
#include "client/include/authentication_kerberos_clientopt-vars.h"
#include "client/include/caching_sha2_passwordopt-vars.h"
#include "client/include/multi_factor_passwordopt-vars.h"
#include "client/include/sslopt-vars.h"
#include "client/include/multi_factor_passwordopt-longopts.h"
#include "client/include/caching_sha2_passwordopt-longopts.h"
#include "client/include/sslopt-longopts.h"
#include "client/include/authentication_kerberos_clientopt-longopts.h"
#include "client/include/sslopt-case.h"
#include "client/include/authentication_kerberos_clientopt-case.h"

Macros

#define DUMP_VERSION   "10.13"
 
#define EX_USAGE   1
 
#define EX_MYSQLERR   2
 
#define EX_CONSCHECK   3
 
#define EX_EOM   4
 
#define EX_EOF   5 /* ferror for output file was got */
 
#define EX_ILLEGAL_TABLE   6
 
#define SHOW_FIELDNAME   0
 
#define SHOW_TYPE   1
 
#define SHOW_NULL   2
 
#define SHOW_DEFAULT   4
 
#define SHOW_EXTRA   5
 
#define QUERY_LENGTH   1536
 
#define COMMENT_LENGTH   2048
 
#define IGNORE_NONE   0x00 /* no ignore */
 
#define IGNORE_DATA   0x01 /* don't dump data for this table */
 
#define MYSQL_UNIVERSAL_CLIENT_CHARSET   "utf8mb4"
 
#define MAX_FIELDS   4000
 
#define LONG_TIMEOUT   (3600UL * 24UL * 365UL)
 
#define FIRST_COLUMN_STATISTICS_VERSION   80002
 
#define FIRST_REPLICA_COMMAND_VERSION   80023
 
#define FIRST_SOURCE_COMMAND_VERSION   80200
 
#define MYSQL_OPT_SOURCE_DATA_EFFECTIVE_SQL   1
 
#define MYSQL_OPT_SOURCE_DATA_COMMENTED_SQL   2
 
#define MYSQL_OPT_REPLICA_DATA_EFFECTIVE_SQL   1
 
#define MYSQL_OPT_REPLICA_DATA_COMMENTED_SQL   2
 
#define DYNAMIC_STR_ERROR_MSG   "Couldn't perform DYNAMIC_STRING operation"
 

Enumerations

enum  enum_set_gtid_purged_mode { SET_GTID_PURGED_OFF = 0 , SET_GTID_PURGED_AUTO = 1 , SET_GTID_PURGED_ON = 2 , SET_GTID_PURGED_COMMENTED = 3 }
 
enum class  Output_as_version_mode { SERVER = 0 , BEFORE_8_0_23 = 1 , BEFORE_8_2_0 = 2 }
 

Functions

static void add_load_option (DYNAMIC_STRING *str, const char *option, const char *option_value)
 
static char * alloc_query_str (size_t size)
 
static void field_escape (DYNAMIC_STRING *in, const char *from)
 
static int parse_ignore_error ()
 Parse the list of error numbers to be ignored and store into a dynamic array. More...
 
static void init_dynamic_string_checked (DYNAMIC_STRING *str, const char *init_str, size_t init_alloc)
 
static void dynstr_append_checked (DYNAMIC_STRING *dest, const char *src)
 
static void dynstr_set_checked (DYNAMIC_STRING *str, const char *init_str)
 
static void dynstr_append_mem_checked (DYNAMIC_STRING *str, const char *append, size_t length)
 
static void dynstr_realloc_checked (DYNAMIC_STRING *str, size_t additional_size)
 
static void maybe_exit (int error)
 
static void die (int error, const char *reason,...)
 
static void maybe_die (int error, const char *reason,...)
 
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)
 
static int init_dumping_views (char *)
 
static int init_dumping_tables (char *)
 
static int init_dumping (char *, int init_func(char *))
 
static int dump_databases (char **)
 
static int dump_all_databases ()
 
static char * quote_name (char *name, char *buff, bool force)
 
static const char * quote_name (const char *name, char *buff, bool force)
 
char check_if_ignore_table (const char *table_name, char *table_type)
 
bool is_infoschema_db (const char *db)
 Check if the database is 'information_schema' and write a verbose message stating that dumping the database is not supported. More...
 
static char * primary_key_fields (const char *table_name)
 
static bool get_view_structure (char *table, char *db)
 
static bool dump_all_views_in_db (char *database)
 
static bool get_gtid_mode (MYSQL *mysql_con)
 This function checks if GTIDs are enabled on the server. More...
 
static Output_as_version_mode get_output_as_version_mode ()
 This function checks what should be the outputted terminology according to the server version. More...
 
static int set_terminology_use_previous_session_value (MYSQL *mysql_con, Output_as_version_mode mode_to_set)
 This method will set depending on the arguments given the server value for terminology_use_previous. More...
 
static int dump_all_tablespaces ()
 
static int dump_tablespaces_for_tables (char *db, char **table_names, int tables)
 
static int dump_tablespaces_for_databases (char **databases)
 
static int dump_tablespaces (char *ts_where)
 
static void print_comment (FILE *sql_file, bool is_error, const char *format,...)
 
static void verbose_msg (const char *fmt,...)
 
static char const * fix_identifier_with_newline (char const *object_name, bool *freemem)
 Accepts object names and prefixes them with "-- " wherever end-of-line character ('
') is found. More...
 
static string get_compatible_rpl_source_query (string command)
 
static string get_compatible_rpl_replica_query (string command)
 
static string get_compatible_rpl_replica_command (string command)
 
static void check_io (FILE *file)
 
static void short_usage_sub (void)
 
static void usage (void)
 
static void short_usage (void)
 
static void get_safe_server_info (char *safe_server_info, size_t safe_server_info_len)
 
static void write_footer (FILE *sql_file)
 
static bool get_one_option (int optid, const struct my_option *opt, char *argument)
 
static int get_options (int *argc, char ***argv)
 
static void DB_error (MYSQL *mysql_arg, const char *when)
 
static int mysql_query_with_error_report (MYSQL *mysql_con, MYSQL_RES **res, const char *query)
 
static int fetch_db_collation (const char *db_name, char *db_cl_name, int db_cl_size)
 
static char * my_case_str (char *str, size_t str_len, const char *token, size_t token_len)
 
static int switch_db_collation (FILE *sql_file, const char *db_name, const char *delimiter, const char *current_db_cl_name, const char *required_db_cl_name, int *db_cl_altered)
 
static int restore_db_collation (FILE *sql_file, const char *db_name, const char *delimiter, const char *db_cl_name)
 
static void switch_cs_variables (FILE *sql_file, const char *delimiter, const char *character_set_client, const char *character_set_results, const char *collation_connection)
 
static void restore_cs_variables (FILE *sql_file, const char *delimiter)
 
static void switch_sql_mode (FILE *sql_file, const char *delimiter, const char *sql_mode)
 
static void restore_sql_mode (FILE *sql_file, const char *delimiter)
 
static void switch_time_zone (FILE *sql_file, const char *delimiter, const char *time_zone)
 
static void restore_time_zone (FILE *sql_file, const char *delimiter)
 
static int switch_character_set_results (MYSQL *mysql, const char *cs_name)
 Switch charset for results to some specified charset. More...
 
static char * cover_definer_clause (char *stmt_str, size_t stmt_length, const char *definer_version_str, size_t definer_version_length, const char *stmt_version_str, size_t stmt_version_length, const char *keyword_str, size_t keyword_length)
 Rewrite statement, enclosing DEFINER clause in version-specific comment. More...
 
static FILE * open_sql_file_for_table (const char *table, int flags)
 
static void free_resources ()
 
static bool do_ignore_error ()
 Check if the last error should be ignored. More...
 
static int connect_to_db (char *host, char *user)
 
static void dbDisconnect (char *host)
 
static void unescape (FILE *file, char *pos, size_t length)
 
static bool test_if_special_chars (const char *str)
 
static char * quote_for_like (const char *name, char *buff)
 
static void print_quoted_xml (FILE *xml_file, const char *str, size_t len, bool is_attribute_name)
 Quote and print a string. More...
 
static void print_xml_tag (FILE *xml_file, const char *sbeg, const char *line_end, const char *tag_name, const char *first_attribute_name,...)
 
static void print_xml_null_tag (FILE *xml_file, const char *sbeg, const char *stag_atr, const char *sval, const char *line_end)
 
static void print_xml_cdata (FILE *xml_file, const char *str, ulong len)
 Print xml CDATA section. More...
 
static void print_xml_row (FILE *xml_file, const char *row_name, MYSQL_RES *tableRes, MYSQL_ROW *row, const char *str_create)
 
static void print_xml_comment (FILE *xml_file, size_t len, const char *comment_string)
 Print xml comments. More...
 
static char * create_delimiter (char *query, char *delimiter_buff, int delimiter_max_size)
 
static void fprintf_string (char *row, ulong row_len, char quote, bool needs_newline)
 
static bool is_string_integer (const char *str, ulong str_len)
 
static uint dump_events_for_db (char *db)
 
static void print_blob_as_hex (FILE *output_file, const char *str, ulong len)
 
static uint dump_routines_for_db (char *db)
 
static bool general_log_or_slow_log_tables (const char *db, const char *table)
 
static bool replication_metadata_tables (const char *db, const char *table)
 
static bool innodb_stats_tables (const char *db, const char *table)
 Check if the table is innodb stats table in mysql database. More...
 
static bool is_innodb_stats_tables_included (int argc, char **argv)
 Check if the command line option includes innodb stats table or in any way mysql database. More...
 
static uint get_table_structure (const char *table, char *db, char *table_type, char *ignore_flag, bool real_columns[], std::string *column_list)
 
static void dump_trigger_old (FILE *sql_file, MYSQL_RES *show_triggers_rs, MYSQL_ROW *show_trigger_row, const char *table_name)
 
static int dump_trigger (FILE *sql_file, MYSQL_RES *show_create_trigger_rs, const char *db_name, const char *db_cl_name)
 
static int dump_triggers_for_table (char *table_name, char *db_name)
 Dump the triggers for a given table. More...
 
static bool dump_column_statistics_for_table (char *table_name, char *db_name)
 
static void dump_table (char *table, char *db)
 
static char * getTableName (int reset)
 
static int is_ndbinfo (MYSQL *mysql, const char *dbname)
 
static bool include_table (const char *hash_key, size_t len)
 
static char * get_actual_table_name (const char *old_table_name, MEM_ROOT *root)
 
static int do_show_binary_log_status (MYSQL *mysql_con)
 
static int do_stop_replica_sql (MYSQL *mysql_con)
 
static int add_stop_replica (void)
 
static int add_replica_statements (void)
 
static int do_show_replica_status (MYSQL *mysql_con)
 
static int do_start_replica_sql (MYSQL *mysql_con)
 
static int do_flush_tables_read_lock (MYSQL *mysql_con)
 
static int do_unlock_tables (MYSQL *mysql_con)
 
static int get_bin_log_name (MYSQL *mysql_con, char *buff_log_name, uint buff_len)
 
static int purge_bin_logs_to (MYSQL *mysql_con, char *log_name)
 
static int start_transaction (MYSQL *mysql_con)
 
static int replace (DYNAMIC_STRING *ds_str, const char *search_str, size_t search_len, const char *replace_str, size_t replace_len)
 
static void set_session_binlog (bool flag)
 This function sets the session binlog in the dump file. More...
 
static bool add_set_gtid_purged (MYSQL *mysql_con)
 This function gets the GTID_EXECUTED sets from the server and assigns those sets to GTID_PURGED in the dump file. More...
 
static bool process_set_gtid_purged (MYSQL *mysql_con, bool is_gtid_enabled)
 This function processes the opt_set_gtid_purged option. More...
 
int main (int argc, char **argv)
 

Variables

static bool verbose = false
 
static bool opt_no_create_info = false
 
static bool opt_no_data = false
 
static bool quick = true
 
static bool extended_insert = true
 
static bool lock_tables = true
 
static bool opt_force = false
 
static bool flush_logs = false
 
static bool flush_privileges = false
 
static bool opt_drop = true
 
static bool opt_keywords = false
 
static bool opt_lock = true
 
static bool opt_compress = false
 
static bool create_options = true
 
static bool opt_quoted = false
 
static bool opt_databases = false
 
static bool opt_alldbs = false
 
static bool opt_create_db = false
 
static bool opt_lock_all_tables = false
 
static bool opt_set_charset = false
 
static bool opt_dump_date = true
 
static bool opt_autocommit = false
 
static bool opt_disable_keys = true
 
static bool opt_xml = false
 
static bool opt_delete_source_logs = false
 
static bool opt_single_transaction = false
 
static bool opt_comments = false
 
static bool opt_compact = false
 
static bool opt_hex_blob = false
 
static bool opt_order_by_primary = false
 
static bool opt_ignore = false
 
static bool opt_complete_insert = false
 
static bool opt_drop_database = false
 
static bool opt_replace_into = false
 
static bool opt_dump_triggers = false
 
static bool opt_routines = false
 
static bool opt_tz_utc = true
 
static bool opt_replica_apply = false
 
static bool opt_include_source_host_port = false
 
static bool opt_events = false
 
static bool opt_comments_used = false
 
static bool opt_alltspcs = false
 
static bool opt_notspcs = false
 
static bool opt_drop_trigger = false
 
static bool opt_network_timeout = false
 
static bool stats_tables_included = false
 
static bool column_statistics = false
 
static bool opt_show_create_table_skip_secondary_engine = false
 
static bool opt_ignore_views = false
 
static bool insert_pat_inited = false
 
static bool debug_info_flag = false
 
static bool debug_check_flag = false
 
static ulong opt_max_allowed_packet
 
static ulong opt_net_buffer_length
 
static MYSQL mysql_connection
 
static MYSQLmysql = nullptr
 
static DYNAMIC_STRING insert_pat
 
static char * current_user = nullptr
 
static char * current_host = nullptr
 
static char * path = nullptr
 
static char * fields_terminated = nullptr
 
static char * lines_terminated = nullptr
 
static char * enclosed = nullptr
 
static char * opt_enclosed = nullptr
 
static char * escaped = nullptr
 
static char * where = nullptr
 
static char * opt_compatible_mode_str = nullptr
 
static char * opt_ignore_error = nullptr
 
static char * log_error_file = nullptr
 
static Multi_option opt_init_commands
 
static MEM_ROOT argv_alloc {PSI_NOT_INSTRUMENTED, 512}
 
static bool ansi_mode = false
 Force the "ANSI" SQL_MODE. More...
 
static bool server_supports_switching_charsets = true
 
static bool ansi_quotes_mode = false
 Use double quotes ("") like in the standard to quote identifiers if true, otherwise backticks (``, non-standard MySQL feature). More...
 
static uint opt_zstd_compress_level = default_zstd_compression_level
 
static char * opt_compress_algorithm = nullptr
 
static uint opt_enable_cleartext_plugin = 0
 
static bool using_opt_enable_cleartext_plugin = false
 
static uint opt_mysql_port = 0
 
static uint opt_source_data
 
static uint opt_replica_data
 
static ulong opt_long_query_time = 0
 
static bool long_query_time_opt_provided = false
 
static uint my_end_arg
 
static char * opt_mysql_unix_port = nullptr
 
static char * opt_bind_addr = nullptr
 
static int first_error = 0
 
FILE * md_result_file = nullptr
 
FILE * stderror_file = nullptr
 
const char * set_gtid_purged_mode_names []
 
static TYPELIB set_gtid_purged_mode_typelib
 
static enum enum_set_gtid_purged_mode opt_set_gtid_purged_mode = SET_GTID_PURGED_AUTO
 
static uint opt_protocol = 0
 
static char * opt_plugin_dir = nullptr
 
static char * opt_default_auth = nullptr
 
static bool opt_skip_gipk = false
 
const char * set_output_as_version_mode []
 
static TYPELIB set_output_as_version_mode_typelib
 
static ulong opt_server_version {0}
 
enum Output_as_version_mode opt_output_as_version_mode = Output_as_version_mode::SERVER
 
Prealloced_array< uint, 12 > ignore_error (PSI_NOT_INSTRUMENTED)
 
static const char * mysql_universal_client_charset
 
static const char * default_charset
 
static CHARSET_INFOcharset_info = &my_charset_latin1
 
const char * default_dbug_option = "d:t:o,/tmp/mysqldump.trace"
 
bool seen_views = false
 
collation_unordered_set< string > * ignore_table
 
static struct my_option my_long_options []
 
static const char * load_default_groups [] = {"mysqldump", "client", nullptr}
 
static std::unordered_map< string, string > compatibility_rpl_replica_commands
 
static std::unordered_map< string, string > compatibility_rpl_source_commands
 

Macro Definition Documentation

◆ COMMENT_LENGTH

#define COMMENT_LENGTH   2048

◆ DUMP_VERSION

#define DUMP_VERSION   "10.13"

◆ DYNAMIC_STR_ERROR_MSG

#define DYNAMIC_STR_ERROR_MSG   "Couldn't perform DYNAMIC_STRING operation"

◆ EX_CONSCHECK

#define EX_CONSCHECK   3

◆ EX_EOF

#define EX_EOF   5 /* ferror for output file was got */

◆ EX_EOM

#define EX_EOM   4

◆ EX_ILLEGAL_TABLE

#define EX_ILLEGAL_TABLE   6

◆ EX_MYSQLERR

#define EX_MYSQLERR   2

◆ EX_USAGE

#define EX_USAGE   1

◆ FIRST_COLUMN_STATISTICS_VERSION

#define FIRST_COLUMN_STATISTICS_VERSION   80002

◆ FIRST_REPLICA_COMMAND_VERSION

#define FIRST_REPLICA_COMMAND_VERSION   80023

◆ FIRST_SOURCE_COMMAND_VERSION

#define FIRST_SOURCE_COMMAND_VERSION   80200

◆ IGNORE_DATA

#define IGNORE_DATA   0x01 /* don't dump data for this table */

◆ IGNORE_NONE

#define IGNORE_NONE   0x00 /* no ignore */

◆ LONG_TIMEOUT

#define LONG_TIMEOUT   (3600UL * 24UL * 365UL)

◆ MAX_FIELDS

#define MAX_FIELDS   4000

◆ MYSQL_OPT_REPLICA_DATA_COMMENTED_SQL

#define MYSQL_OPT_REPLICA_DATA_COMMENTED_SQL   2

◆ MYSQL_OPT_REPLICA_DATA_EFFECTIVE_SQL

#define MYSQL_OPT_REPLICA_DATA_EFFECTIVE_SQL   1

◆ MYSQL_OPT_SOURCE_DATA_COMMENTED_SQL

#define MYSQL_OPT_SOURCE_DATA_COMMENTED_SQL   2

◆ MYSQL_OPT_SOURCE_DATA_EFFECTIVE_SQL

#define MYSQL_OPT_SOURCE_DATA_EFFECTIVE_SQL   1

◆ MYSQL_UNIVERSAL_CLIENT_CHARSET

#define MYSQL_UNIVERSAL_CLIENT_CHARSET   "utf8mb4"

◆ QUERY_LENGTH

#define QUERY_LENGTH   1536

◆ SHOW_DEFAULT

#define SHOW_DEFAULT   4

◆ SHOW_EXTRA

#define SHOW_EXTRA   5

◆ SHOW_FIELDNAME

#define SHOW_FIELDNAME   0

◆ SHOW_NULL

#define SHOW_NULL   2

◆ SHOW_TYPE

#define SHOW_TYPE   1

Enumeration Type Documentation

◆ enum_set_gtid_purged_mode

Enumerator
SET_GTID_PURGED_OFF 
SET_GTID_PURGED_AUTO 
SET_GTID_PURGED_ON 
SET_GTID_PURGED_COMMENTED 

◆ Output_as_version_mode

enum class Output_as_version_mode
strong
Enumerator
SERVER 
BEFORE_8_0_23 

Output command terminology matching the dumped server.

BEFORE_8_2_0 

Output command terminology for servers below 8.0.23.

Function Documentation

◆ add_load_option()

static void add_load_option ( DYNAMIC_STRING str,
const char *  option,
const char *  option_value 
)
static

◆ add_replica_statements()

static int add_replica_statements ( void  )
static

◆ add_set_gtid_purged()

static bool add_set_gtid_purged ( MYSQL mysql_con)
static

This function gets the GTID_EXECUTED sets from the server and assigns those sets to GTID_PURGED in the dump file.

Parameters
[in]mysql_conconnection to the server
Return values
falsesuccessfully printed GTID_PURGED sets in the dump file.
truefailed.

◆ add_stop_replica()

static int add_stop_replica ( void  )
static

◆ alloc_query_str()

static char * alloc_query_str ( size_t  size)
static

◆ check_if_ignore_table()

char check_if_ignore_table ( const char *  table_name,
char *  table_type 
)

◆ check_io()

static void check_io ( FILE *  file)
static

◆ connect_to_db()

static int connect_to_db ( char *  host,
char *  user 
)
static

◆ cover_definer_clause()

static char * cover_definer_clause ( char *  stmt_str,
size_t  stmt_length,
const char *  definer_version_str,
size_t  definer_version_length,
const char *  stmt_version_str,
size_t  stmt_version_length,
const char *  keyword_str,
size_t  keyword_length 
)
static

Rewrite statement, enclosing DEFINER clause in version-specific comment.

This function parses any CREATE statement and encloses DEFINER-clause in version-specific comment: input query: CREATE DEFINER=aFUNCTION ... rewritten query: CREATE * / / *!50020 DEFINER=a* / / *!50003 FUNCTION ...

Note
This function will go away when WL#3995 is implemented.
Parameters
[in]stmt_strCREATE statement string.
[in]stmt_lengthLength of the stmt_str.
[in]definer_version_strMinimal MySQL version number when DEFINER clause is supported in the given statement.
[in]definer_version_lengthLength of definer_version_str.
[in]stmt_version_strMinimal MySQL version number when the given statement is supported.
[in]stmt_version_lengthLength of stmt_version_str.
[in]keyword_strKeyword to look for after CREATE.
[in]keyword_lengthLength of keyword_str.
Returns
pointer to the new allocated query string.

◆ create_delimiter()

static char * create_delimiter ( char *  query,
char *  delimiter_buff,
int  delimiter_max_size 
)
static

◆ DB_error()

static void DB_error ( MYSQL mysql_arg,
const char *  when 
)
static

◆ dbDisconnect()

static void dbDisconnect ( char *  host)
static

◆ die()

static void die ( int  error,
const char *  reason,
  ... 
)
static

◆ do_flush_tables_read_lock()

static int do_flush_tables_read_lock ( MYSQL mysql_con)
static

◆ do_ignore_error()

static bool do_ignore_error ( )
static

Check if the last error should be ignored.

Return values
1yes 0 no

◆ do_show_binary_log_status()

static int do_show_binary_log_status ( MYSQL mysql_con)
static

◆ do_show_replica_status()

static int do_show_replica_status ( MYSQL mysql_con)
static

◆ do_start_replica_sql()

static int do_start_replica_sql ( MYSQL mysql_con)
static

◆ do_stop_replica_sql()

static int do_stop_replica_sql ( MYSQL mysql_con)
static

◆ do_unlock_tables()

static int do_unlock_tables ( MYSQL mysql_con)
static

◆ dump_all_databases()

static int dump_all_databases ( )
static

◆ dump_all_tables_in_db()

static int dump_all_tables_in_db ( char *  db)
static

ROLLBACK TO SAVEPOINT in –single-transaction mode to release metadata lock on table which was already dumped. This allows to avoid blocking concurrent DDL on this table without sacrificing correctness, as we won't access table second time and dumps created by –single-transaction mode have validity point at the start of transaction anyway. Note that this doesn't make –single-transaction mode with concurrent DDL safe in general case. It just improves situation for people for whom it might be working.

◆ dump_all_tablespaces()

static int dump_all_tablespaces ( )
static

◆ dump_all_views_in_db()

static bool dump_all_views_in_db ( char *  database)
static

◆ dump_column_statistics_for_table()

static bool dump_column_statistics_for_table ( char *  table_name,
char *  db_name 
)
static

◆ dump_databases()

static int dump_databases ( char **  db_names)
static

◆ dump_events_for_db()

static uint dump_events_for_db ( char *  db)
static

◆ dump_routines_for_db()

static uint dump_routines_for_db ( char *  db)
static

◆ dump_selected_tables()

static int dump_selected_tables ( char *  db,
char **  table_names,
int  tables 
)
static

ROLLBACK TO SAVEPOINT in –single-transaction mode to release metadata lock on table which was already dumped. This allows to avoid blocking concurrent DDL on this table without sacrificing correctness, as we won't access table second time and dumps created by –single-transaction mode have validity point at the start of transaction anyway. Note that this doesn't make –single-transaction mode with concurrent DDL safe in general case. It just improves situation for people for whom it might be working.

◆ dump_table()

static void dump_table ( char *  table,
char *  db 
)
static

◆ dump_tablespaces()

static int dump_tablespaces ( char *  ts_where)
static

◆ dump_tablespaces_for_databases()

static int dump_tablespaces_for_databases ( char **  databases)
static

◆ dump_tablespaces_for_tables()

static int dump_tablespaces_for_tables ( char *  db,
char **  table_names,
int  tables 
)
static

◆ dump_trigger()

static int dump_trigger ( FILE *  sql_file,
MYSQL_RES show_create_trigger_rs,
const char *  db_name,
const char *  db_cl_name 
)
static

◆ dump_trigger_old()

static void dump_trigger_old ( FILE *  sql_file,
MYSQL_RES show_triggers_rs,
MYSQL_ROW show_trigger_row,
const char *  table_name 
)
static

◆ dump_triggers_for_table()

static int dump_triggers_for_table ( char *  table_name,
char *  db_name 
)
static

Dump the triggers for a given table.

This should be called after the tables have been dumped in case a trigger depends on the existence of a table.

Parameters
[in]table_nametable name
[in]db_namedb name
Returns
Error status.
Return values
trueerror has occurred.
falseoperation succeed.

◆ dynstr_append_checked()

static void dynstr_append_checked ( DYNAMIC_STRING dest,
const char *  src 
)
static

◆ dynstr_append_mem_checked()

static void dynstr_append_mem_checked ( DYNAMIC_STRING str,
const char *  append,
size_t  length 
)
static

◆ dynstr_realloc_checked()

static void dynstr_realloc_checked ( DYNAMIC_STRING str,
size_t  additional_size 
)
static

◆ dynstr_set_checked()

static void dynstr_set_checked ( DYNAMIC_STRING str,
const char *  init_str 
)
static

◆ fetch_db_collation()

static int fetch_db_collation ( const char *  db_name,
char *  db_cl_name,
int  db_cl_size 
)
static

◆ field_escape()

static void field_escape ( DYNAMIC_STRING in,
const char *  from 
)
static

◆ fix_identifier_with_newline()

static char const * fix_identifier_with_newline ( char const *  object_name,
bool *  freemem 
)
static

Accepts object names and prefixes them with "-- " wherever end-of-line character ('
') is found.

Parameters
[in]object_nameobject name list (concatenated string)
[out]freememshould buffer be released after usage
Returns
pointer to a string with prefixed objects

◆ fprintf_string()

static void fprintf_string ( char *  row,
ulong  row_len,
char  quote,
bool  needs_newline 
)
static

◆ free_resources()

static void free_resources ( )
static

◆ general_log_or_slow_log_tables()

static bool general_log_or_slow_log_tables ( const char *  db,
const char *  table 
)
inlinestatic

◆ get_actual_table_name()

static char * get_actual_table_name ( const char *  old_table_name,
MEM_ROOT root 
)
static

◆ get_bin_log_name()

static int get_bin_log_name ( MYSQL mysql_con,
char *  buff_log_name,
uint  buff_len 
)
static

◆ get_compatible_rpl_replica_command()

static string get_compatible_rpl_replica_command ( string  command)
static

◆ get_compatible_rpl_replica_query()

static string get_compatible_rpl_replica_query ( string  command)
static

◆ get_compatible_rpl_source_query()

static string get_compatible_rpl_source_query ( string  command)
static

◆ get_gtid_mode()

static bool get_gtid_mode ( MYSQL mysql_con)
static

This function checks if GTIDs are enabled on the server.

Parameters
[in]mysql_conthe connection to the server
Return values
trueif GTIDs are enabled on the server
falseif GTIDs are disabled on the server

◆ get_one_option()

static bool get_one_option ( int  optid,
const struct my_option opt,
char *  argument 
)
static

◆ get_options()

static int get_options ( int *  argc,
char ***  argv 
)
static

◆ get_output_as_version_mode()

static Output_as_version_mode get_output_as_version_mode ( )
static

This function checks what should be the outputted terminology according to the server version.

Return values
SERVERif no compatibility mode is needed
BEFORE_8_0_23if the server version is lower than 8.0.23
BEFORE_8_2_0if the server version is lower than 8.2.0

◆ get_safe_server_info()

static void get_safe_server_info ( char *  safe_server_info,
size_t  safe_server_info_len 
)
static

◆ get_table_structure()

static uint get_table_structure ( const char *  table,
char *  db,
char *  table_type,
char *  ignore_flag,
bool  real_columns[],
std::string *  column_list 
)
static

◆ get_view_structure()

static bool get_view_structure ( char *  table,
char *  db 
)
static

◆ getTableName()

static char * getTableName ( int  reset)
static

◆ include_table()

static bool include_table ( const char *  hash_key,
size_t  len 
)
static

◆ init_dumping()

static int init_dumping ( char *  database,
int   init_funcchar * 
)
static

◆ init_dumping_tables()

int init_dumping_tables ( char *  qdatabase)
static

◆ init_dumping_views()

int init_dumping_views ( char *  qdatabase)
static

◆ init_dynamic_string_checked()

static void init_dynamic_string_checked ( DYNAMIC_STRING str,
const char *  init_str,
size_t  init_alloc 
)
static

◆ innodb_stats_tables()

static bool innodb_stats_tables ( const char *  db,
const char *  table 
)
inlinestatic

Check if the table is innodb stats table in mysql database.

Parameters
[in]dbDatabase name
[in]tableTable name
Return values
trueif it is innodb stats table else false

◆ is_infoschema_db()

bool is_infoschema_db ( const char *  db)

Check if the database is 'information_schema' and write a verbose message stating that dumping the database is not supported.

Parameters
dbDatabase Name.
Return values
trueIf database should be ignored.
falseIf database shouldn't be ignored.

◆ is_innodb_stats_tables_included()

static bool is_innodb_stats_tables_included ( int  argc,
char **  argv 
)
inlinestatic

Check if the command line option includes innodb stats table or in any way mysql database.

Parameters
[in]argcTotal count of positional arguments
[in]argvPointer to positional arguments
Return values
trueif dump contains innodb stats table or else false

◆ is_ndbinfo()

static int is_ndbinfo ( MYSQL mysql,
const char *  dbname 
)
static

◆ is_string_integer()

static bool is_string_integer ( const char *  str,
ulong  str_len 
)
static

◆ main()

int main ( int  argc,
char **  argv 
)

◆ maybe_die()

static void maybe_die ( int  error,
const char *  reason,
  ... 
)
static

◆ maybe_exit()

static void maybe_exit ( int  error)
static

◆ my_case_str()

static char * my_case_str ( char *  str,
size_t  str_len,
const char *  token,
size_t  token_len 
)
static

◆ mysql_query_with_error_report()

static int mysql_query_with_error_report ( MYSQL mysql_con,
MYSQL_RES **  res,
const char *  query 
)
static

◆ open_sql_file_for_table()

static FILE * open_sql_file_for_table ( const char *  table,
int  flags 
)
static

◆ parse_ignore_error()

static int parse_ignore_error ( )
static

Parse the list of error numbers to be ignored and store into a dynamic array.

Returns
Operation status
Return values
0Success
>0Failure

◆ primary_key_fields()

static char * primary_key_fields ( const char *  table_name)
static

◆ print_blob_as_hex()

static void print_blob_as_hex ( FILE *  output_file,
const char *  str,
ulong  len 
)
static

◆ print_comment()

static void print_comment ( FILE *  sql_file,
bool  is_error,
const char *  format,
  ... 
)
static

◆ print_quoted_xml()

static void print_quoted_xml ( FILE *  xml_file,
const char *  str,
size_t  len,
bool  is_attribute_name 
)
static

Quote and print a string.

Quote '<' '>' '&' '"' chars and print a string to the xml_file.

Parameters
xml_fileOutput file.
strString to print.
lenIts length.
is_attribute_nameA check for attribute name or value.

◆ print_value()

static void print_value ( FILE *  file,
MYSQL_RES result,
MYSQL_ROW  row,
const char *  prefix,
const char *  name,
int  string_value 
)
static

◆ print_xml_cdata()

static void print_xml_cdata ( FILE *  xml_file,
const char *  str,
ulong  len 
)
static

Print xml CDATA section.

Parameters
xml_file- output file
str- string to print
len- length of the string
Note
This function also takes care of the presence of '[[>' string in the str. If found, the CDATA section is broken into two CDATA sections, ]] and >]].

◆ print_xml_comment()

static void print_xml_comment ( FILE *  xml_file,
size_t  len,
const char *  comment_string 
)
static

Print xml comments.

Print the comment message in the format: "<!-- \n comment string \n -->\n"

Parameters
xml_fileoutput file
lenlength of comment message
comment_stringcomment message
Note
Any occurrence of continuous hyphens will be squeezed to a single hyphen.

◆ print_xml_null_tag()

static void print_xml_null_tag ( FILE *  xml_file,
const char *  sbeg,
const char *  stag_atr,
const char *  sval,
const char *  line_end 
)
static

◆ print_xml_row()

static void print_xml_row ( FILE *  xml_file,
const char *  row_name,
MYSQL_RES tableRes,
MYSQL_ROW row,
const char *  str_create 
)
static

◆ print_xml_tag()

static void print_xml_tag ( FILE *  xml_file,
const char *  sbeg,
const char *  line_end,
const char *  tag_name,
const char *  first_attribute_name,
  ... 
)
static

◆ process_set_gtid_purged()

static bool process_set_gtid_purged ( MYSQL mysql_con,
bool  is_gtid_enabled 
)
static

This function processes the opt_set_gtid_purged option.

This function also calls set_session_binlog() function before setting the SET @GLOBAL.GTID_PURGED in the output.

Parameters
[in]mysql_conthe connection to the server
[in]is_gtid_enabledtrue if server has gtid_mode on
Return values
falsesuccessful according to the value of opt_set_gtid_purged.
truefail.

◆ purge_bin_logs_to()

static int purge_bin_logs_to ( MYSQL mysql_con,
char *  log_name 
)
static

◆ quote_for_like()

static char * quote_for_like ( const char *  name,
char *  buff 
)
static

◆ quote_name() [1/2]

static char * quote_name ( char *  name,
char *  buff,
bool  force 
)
static

◆ quote_name() [2/2]

static const char * quote_name ( const char *  name,
char *  buff,
bool  force 
)
static

◆ replace()

static int replace ( DYNAMIC_STRING ds_str,
const char *  search_str,
size_t  search_len,
const char *  replace_str,
size_t  replace_len 
)
static

◆ replication_metadata_tables()

static bool replication_metadata_tables ( const char *  db,
const char *  table 
)
inlinestatic

◆ restore_cs_variables()

static void restore_cs_variables ( FILE *  sql_file,
const char *  delimiter 
)
static

◆ restore_db_collation()

static int restore_db_collation ( FILE *  sql_file,
const char *  db_name,
const char *  delimiter,
const char *  db_cl_name 
)
static

◆ restore_sql_mode()

static void restore_sql_mode ( FILE *  sql_file,
const char *  delimiter 
)
static

◆ restore_time_zone()

static void restore_time_zone ( FILE *  sql_file,
const char *  delimiter 
)
static

◆ set_session_binlog()

static void set_session_binlog ( bool  flag)
static

This function sets the session binlog in the dump file.

When –set-gtid-purged is used, this function is called to disable the session binlog and at the end of the dump, to restore the session binlog.

Note
: md_result_file should have been opened, before this function is called.
Parameters
[in]flagIf false, disable binlog. If true and binlog disabled previously, restore the session binlog.

◆ set_terminology_use_previous_session_value()

static int set_terminology_use_previous_session_value ( MYSQL mysql_con,
Output_as_version_mode  mode_to_set 
)
static

This method will set depending on the arguments given the server value for terminology_use_previous.

Parameters
[in]mysql_conthe connection to the server
[in]mode_to_setwhat mode to set
Return values
1if an query error ocurred, 0 otherwise.

◆ short_usage()

static void short_usage ( void  )
static

◆ short_usage_sub()

static void short_usage_sub ( void  )
static

◆ start_transaction()

static int start_transaction ( MYSQL mysql_con)
static

◆ switch_character_set_results()

static int switch_character_set_results ( MYSQL mysql,
const char *  cs_name 
)
static

Switch charset for results to some specified charset.

If the server does not support character_set_results variable, nothing can be done here. As for whether something should be done here, future new callers of this function should be aware that the server lacking the facility of switching charsets is treated as success.

Note
If the server lacks support, then nothing is changed and no error condition is returned.
Returns
whether there was an error or not

◆ switch_cs_variables()

static void switch_cs_variables ( FILE *  sql_file,
const char *  delimiter,
const char *  character_set_client,
const char *  character_set_results,
const char *  collation_connection 
)
static

◆ switch_db_collation()

static int switch_db_collation ( FILE *  sql_file,
const char *  db_name,
const char *  delimiter,
const char *  current_db_cl_name,
const char *  required_db_cl_name,
int *  db_cl_altered 
)
static

◆ switch_sql_mode()

static void switch_sql_mode ( FILE *  sql_file,
const char *  delimiter,
const char *  sql_mode 
)
static

◆ switch_time_zone()

static void switch_time_zone ( FILE *  sql_file,
const char *  delimiter,
const char *  time_zone 
)
static

◆ test_if_special_chars()

static bool test_if_special_chars ( const char *  str)
static

◆ unescape()

static void unescape ( FILE *  file,
char *  pos,
size_t  length 
)
static

◆ usage()

static void usage ( void  )
static

◆ verbose_msg()

static void verbose_msg ( const char *  fmt,
  ... 
)
static

◆ write_footer()

static void write_footer ( FILE *  sql_file)
static

◆ write_header()

static void write_header ( FILE *  sql_file,
char *  db_name 
)
static

Variable Documentation

◆ ansi_mode

bool ansi_mode = false
static

Force the "ANSI" SQL_MODE.

◆ ansi_quotes_mode

bool ansi_quotes_mode = false
static

Use double quotes ("") like in the standard to quote identifiers if true, otherwise backticks (``, non-standard MySQL feature).

◆ argv_alloc

MEM_ROOT argv_alloc {PSI_NOT_INSTRUMENTED, 512}
static

◆ charset_info

CHARSET_INFO* charset_info = &my_charset_latin1
static

◆ column_statistics

bool column_statistics = false
static

◆ compatibility_rpl_replica_commands

std::unordered_map<string, string> compatibility_rpl_replica_commands
static
Initial value:
= {
{"SHOW REPLICA STATUS", "SHOW SLAVE STATUS"},
{"STOP REPLICA", "STOP SLAVE"},
{"START REPLICA", "START SLAVE"},
{"STOP REPLICA SQL_THREAD", "STOP SLAVE SQL_THREAD"},
{"CHANGE REPLICATION SOURCE TO", "CHANGE MASTER TO"},
{"SOURCE_HOST", "MASTER_HOST"},
{"SOURCE_PORT", "MASTER_PORT"},
{"SOURCE_LOG_FILE", "MASTER_LOG_FILE"},
{"SOURCE_LOG_POS", "MASTER_LOG_POS"}}

◆ compatibility_rpl_source_commands

std::unordered_map<string, string> compatibility_rpl_source_commands
static
Initial value:
= {
{"SHOW BINARY LOG STATUS", "SHOW MASTER STATUS"}}

◆ create_options

bool create_options = true
static

◆ current_host

char * current_host = nullptr
static

◆ current_user

char* current_user = nullptr
static

◆ debug_check_flag

bool debug_check_flag = false
static

◆ debug_info_flag

bool debug_info_flag = false
static

◆ default_charset

const char* default_charset
static

◆ default_dbug_option

const char* default_dbug_option = "d:t:o,/tmp/mysqldump.trace"

◆ enclosed

char * enclosed = nullptr
static

◆ escaped

char * escaped = nullptr
static

◆ extended_insert

bool extended_insert = true
static

◆ fields_terminated

char * fields_terminated = nullptr
static

◆ first_error

int first_error = 0
static

◆ flush_logs

bool flush_logs = false
static

◆ flush_privileges

bool flush_privileges = false
static

◆ ignore_error

◆ ignore_table

collation_unordered_set<string>* ignore_table

◆ insert_pat

DYNAMIC_STRING insert_pat
static

◆ insert_pat_inited

bool insert_pat_inited = false
static

◆ lines_terminated

char * lines_terminated = nullptr
static

◆ load_default_groups

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

◆ lock_tables

bool lock_tables = true
static

◆ log_error_file

char * log_error_file = nullptr
static

◆ long_query_time_opt_provided

bool long_query_time_opt_provided = false
static

◆ md_result_file

FILE* md_result_file = nullptr

◆ my_end_arg

uint my_end_arg
static

◆ my_long_options

struct my_option my_long_options[]
static

◆ mysql

MYSQL * mysql = nullptr
static

◆ mysql_connection

MYSQL mysql_connection
static

◆ mysql_universal_client_charset

const char* mysql_universal_client_charset
static
Initial value:
=
#define MYSQL_UNIVERSAL_CLIENT_CHARSET
Definition: mysqldump.cc:99

◆ opt_alldbs

bool opt_alldbs = false
static

◆ opt_alltspcs

bool opt_alltspcs = false
static

◆ opt_autocommit

bool opt_autocommit = false
static

◆ opt_bind_addr

char* opt_bind_addr = nullptr
static

◆ opt_comments

bool opt_comments = false
static

◆ opt_comments_used

bool opt_comments_used = false
static

◆ opt_compact

bool opt_compact = false
static

◆ opt_compatible_mode_str

char * opt_compatible_mode_str = nullptr
static

◆ opt_complete_insert

bool opt_complete_insert = false
static

◆ opt_compress

bool opt_compress = false
static

◆ opt_compress_algorithm

char* opt_compress_algorithm = nullptr
static

◆ opt_create_db

bool opt_create_db = false
static

◆ opt_databases

bool opt_databases = false
static

◆ opt_default_auth

char * opt_default_auth = nullptr
static

◆ opt_delete_source_logs

bool opt_delete_source_logs = false
static

◆ opt_disable_keys

bool opt_disable_keys = true
static

◆ opt_drop

bool opt_drop = true
static

◆ opt_drop_database

bool opt_drop_database = false
static

◆ opt_drop_trigger

bool opt_drop_trigger = false
static

◆ opt_dump_date

bool opt_dump_date = true
static

◆ opt_dump_triggers

bool opt_dump_triggers = false
static

◆ opt_enable_cleartext_plugin

uint opt_enable_cleartext_plugin = 0
static

◆ opt_enclosed

char * opt_enclosed = nullptr
static

◆ opt_events

bool opt_events = false
static

◆ opt_force

bool opt_force = false
static

◆ opt_hex_blob

bool opt_hex_blob = false
static

◆ opt_ignore

bool opt_ignore = false
static

◆ opt_ignore_error

char * opt_ignore_error = nullptr
static

◆ opt_ignore_views

bool opt_ignore_views = false
static

◆ opt_include_source_host_port

bool opt_include_source_host_port = false
static

◆ opt_init_commands

Multi_option opt_init_commands
static

◆ opt_keywords

bool opt_keywords = false
static

◆ opt_lock

bool opt_lock = true
static

◆ opt_lock_all_tables

bool opt_lock_all_tables = false
static

◆ opt_long_query_time

ulong opt_long_query_time = 0
static

◆ opt_max_allowed_packet

ulong opt_max_allowed_packet
static

◆ opt_mysql_port

uint opt_mysql_port = 0
static

◆ opt_mysql_unix_port

char* opt_mysql_unix_port = nullptr
static

◆ opt_net_buffer_length

ulong opt_net_buffer_length
static

◆ opt_network_timeout

bool opt_network_timeout = false
static

◆ opt_no_create_info

bool opt_no_create_info = false
static

◆ opt_no_data

bool opt_no_data = false
static

◆ opt_notspcs

bool opt_notspcs = false
static

◆ opt_order_by_primary

bool opt_order_by_primary = false
static

◆ opt_output_as_version_mode

enum Output_as_version_mode opt_output_as_version_mode = Output_as_version_mode::SERVER

◆ opt_plugin_dir

char* opt_plugin_dir = nullptr
static

◆ opt_protocol

uint opt_protocol = 0
static

◆ opt_quoted

bool opt_quoted = false
static

◆ opt_replace_into

bool opt_replace_into = false
static

◆ opt_replica_apply

bool opt_replica_apply = false
static

◆ opt_replica_data

uint opt_replica_data
static

◆ opt_routines

bool opt_routines = false
static

◆ opt_server_version

ulong opt_server_version {0}
static

◆ opt_set_charset

bool opt_set_charset = false
static

◆ opt_set_gtid_purged_mode

enum enum_set_gtid_purged_mode opt_set_gtid_purged_mode = SET_GTID_PURGED_AUTO
static

◆ opt_show_create_table_skip_secondary_engine

bool opt_show_create_table_skip_secondary_engine = false
static

◆ opt_single_transaction

bool opt_single_transaction = false
static

◆ opt_skip_gipk

bool opt_skip_gipk = false
static

◆ opt_source_data

uint opt_source_data
static

◆ opt_tz_utc

bool opt_tz_utc = true
static

◆ opt_xml

bool opt_xml = false
static

◆ opt_zstd_compress_level

uint opt_zstd_compress_level = default_zstd_compression_level
static

◆ path

char * path = nullptr
static

◆ quick

bool quick = true
static

◆ seen_views

bool seen_views = false

◆ server_supports_switching_charsets

bool server_supports_switching_charsets = true
static

◆ set_gtid_purged_mode_names

const char* set_gtid_purged_mode_names[]
Initial value:
= {"OFF", "AUTO", "ON", "COMMENTED",
#define NullS
Definition of the null string (a null pointer of type char *), used in some of our string handling co...
Definition: nulls.h:33

◆ set_gtid_purged_mode_typelib

TYPELIB set_gtid_purged_mode_typelib
static
Initial value:
= {
const char * set_gtid_purged_mode_names[]
Definition: mysqldump.cc:190
#define array_elements(A)
Definition: validate_password_imp.cc:48

◆ set_output_as_version_mode

const char* set_output_as_version_mode[]
Initial value:
= {"SERVER", "BEFORE_8_0_23",
"BEFORE_8_2_0", NullS}

◆ set_output_as_version_mode_typelib

TYPELIB set_output_as_version_mode_typelib
static
Initial value:
= {
const char * set_output_as_version_mode[]
Definition: mysqldump.cc:209

◆ stats_tables_included

bool stats_tables_included = false
static

◆ stderror_file

FILE* stderror_file = nullptr

◆ using_opt_enable_cleartext_plugin

bool using_opt_enable_cleartext_plugin = false
static

◆ verbose

bool verbose = false
static

◆ where

char * where = nullptr
static