/* until MDEV-35831 is implemented, we'll have to detect VECTOR by name */ #define MYSQL_TYPE_VECTOR 1 #define MYSQL_TYPE_VERS_COL 2 #define MYSQL_TYPE_GENERATED 4
staticstruct my_option my_long_options[] =
{
{"all-databases", 'A', "Dump all the databases. This will be same as --databases with all databases selected.",
&opt_alldbs, &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"all-tablespaces", 'Y', "Dump all the tablespaces.",
&opt_alltspcs, &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-tablespaces", 'y', "Do not dump any tablespace information.",
&opt_notspcs, &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"add-drop-database", 0, "Add a DROP DATABASE before each create.",
&opt_drop_database, &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"add-drop-table", 0, "Add a DROP TABLE before each create.",
&opt_drop, &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"add-drop-trigger", 0, "Add a DROP TRIGGER before each create.",
&opt_drop_trigger, &opt_drop_trigger, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"add-locks", 0, "Add locks around INSERT statements.",
&opt_lock, &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"allow-keywords", 0, "Allow creation of column names that are keywords.", &opt_keywords,
&opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"apply-slave-statements", 0, "Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
&opt_slave_apply, &opt_slave_apply, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"as-of", 0, "Dump system versioned table(s) as of specified timestamp. " "Argument is interpreted according to the --tz-utc setting. " "Table structures are always dumped as of current timestamp.",
&opt_asof_timestamp, &opt_asof_timestamp, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", 0, "Directory for character set files.", (char **)&charsets_dir,
(char **)&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"comments", 'i', "Write additional information.",
&opt_comments, &opt_comments, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"compatible", OPT_COMPATIBLE, "Change the dump to be compatible with a given mode. By default tables " "are dumped in a format optimized for MariaDB. Legal modes are: ansi, " "mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, " "no_table_options, no_field_options. One can use several modes separated " "by commas. Note: Requires MariaDB server version 4.1.0 or higher. " "This option is ignored with earlier server versions.",
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"compact", OPT_COMPACT, "Give less verbose output (useful for debugging). Disables structure " "comments and header/footer constructs. Enables options --skip-add-" "drop-table --skip-add-locks --skip-comments --skip-disable-keys " "--skip-set-charset.",
&opt_compact, &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"complete-insert", 'c', "Use complete insert statements.",
&opt_complete_insert, &opt_complete_insert, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"compress", 'C', "Use compression in server/client protocol.",
&opt_compress, &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"copy_s3_tables", 0, "If 'no' S3 tables will be ignored, otherwise S3 tables will be copied as " " Aria tables and then altered to S3",
&opt_copy_s3_tables, &opt_copy_s3_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"create-options", 'a', "Include all MariaDB specific create options.",
&create_options, &create_options, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"databases", 'B', "Dump several databases. Note the difference in usage; in this case no " "tables are given. All name arguments are regarded as database names. " "'USE db_name;' will be included in the output.",
&opt_databases, &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"wildcards", 'L', "Usage of wildcards in the table/database name. Without " "option \"databases\" wildcards are only recognized in table names. " "With the \"databases\" option - in databases names.",
&opt_wildcards, &opt_wildcards, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifdef DBUG_OFF
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0}, #else
{"debug", '#', "Output debug log.", (char *)&default_dbug_option,
(char *)&default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"debug-check", 0, "Check memory and open file usage at exit.",
&debug_check_flag, &debug_check_flag, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"debug-info", 0, "Print some debug info at exit.", &debug_info_flag,
&debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"default-character-set", OPT_DEFAULT_CHARSET, "Set the default character set.", &default_charset,
&default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"delayed-insert", 0, "Insert rows with INSERT DELAYED.",
&opt_delayed, &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"delete-master-logs", 0, "Delete logs on master after backup. This automatically enables --master-data.",
&opt_delete_master_logs, &opt_delete_master_logs, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"dir", 'D', "directory to store the backup. Table data is stored in tab-separated file, similar to --tab option," "in a subdirectory with database name.",
&opt_dir, &opt_dir, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"disable-keys", 'K', "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER " "TABLE tb_name ENABLE KEYS */; will be put in the output.", &opt_disable_keys,
&opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"dump-date", 0, "Put a dump date to the end of the output.",
&opt_dump_date, &opt_dump_date, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"dump-history", 'H', "Dump system-versioned tables with history (only for " "timestamp based versioning). Use also --update-history if " "upgrading to MariaDB 11.5 or newer from a version before 11.5",
&opt_dump_history, &opt_dump_history, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"update-history", OPT_UPDATE_HISTORY, "Update row_end history timestamp to support dates up to year 2106. " "This option will also enable tz-utc. " "Should be used when upgrading to MariaDB 11.5 or above.",
&opt_update_history, &opt_update_history, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA, "This causes the binary log position and filename of the master to be " "appended to the dumped data output. Setting the value to 1, will print" "it as a CHANGE MASTER command in the dumped data output; if equal" " to 2, that command will be prefixed with a comment symbol. " "This option will turn --lock-all-tables on, unless " "--single-transaction is specified too (in which case a " "global read lock is only taken a short time at the beginning of the dump " "- don't forget to read about --single-transaction below). In all cases " "any action on logs will happen at the exact moment of the dump." "Option automatically turns --lock-tables off.",
&opt_slave_data, &opt_slave_data, 0,
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
{"events", 'E', "Dump events.", &opt_events, &opt_events, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"extended-insert", 'e', "Use multiple-row INSERT syntax that include several VALUES lists.",
&extended_insert, &extended_insert, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"fields-terminated-by", 0, "Fields in the output file are terminated by the given string.",
&fields_terminated, &fields_terminated, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"fields-enclosed-by", 0, "Fields in the output file are enclosed by the given character.",
&enclosed, &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
{"fields-optionally-enclosed-by", 0, "Fields in the output file are optionally enclosed by the given character.",
&opt_enclosed, &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
{"fields-escaped-by", 0, "Fields in the output file are escaped by the given character.",
&escaped, &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"flush-logs", 'F', "Flush logs file in server before starting dump. " "Note that if you dump many databases at once (using the option " "--databases= or --all-databases), the logs will be flushed for " "each database dumped. The exception is when using --lock-all-tables " "or --master-data: " "in this case the logs will be flushed only once, corresponding " "to the moment all tables are locked. So if you want your dump and " "the log flush to happen at the same exact moment you should use " "--lock-all-tables or --master-data with --flush-logs.",
&flush_logs, &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"flush-privileges", 0, "Emit a FLUSH PRIVILEGES statement " "after dumping the mysql database. This option should be used any " "time the dump contains the mysql database and any other database " "that depends on the data in the mysql database for proper restore. ",
&flush_privileges, &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f', "Continue even if we get an SQL error.",
&ignore_errors, &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"gtid", 0, "Used together with --master-data=1 or --dump-slave=1." "When enabled, the output from those options will set the GTID position " "instead of the binlog file and offset; the file/offset will appear only as " "a comment. When disabled, the GTID position will still appear in the " "output, but only commented.",
&opt_use_gtid, &opt_use_gtid, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"header", 0, "Used together with --tab. When enabled, adds header with column names to the top of output txt files.",
&opt_header, &opt_header, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"hex-blob", 0, "Dump binary strings (BINARY, " "VARBINARY, BLOB) in hexadecimal format.",
&opt_hex_blob, &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host. Defaults in the following order: " "$MARIADB_HOST, and then localhost",
¤t_host, ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"ignore-database", OPT_IGNORE_DATABASE, "Do not dump the specified database. To specify more than one database to ignore, " "use the directive multiple times, once for each database. Only takes effect " "when used together with --all-databases or --wildcards --databases.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"ignore-table-data", OPT_IGNORE_DATA, "Do not dump the specified table data. To specify more than one table " "to ignore, use the directive multiple times, once for each table. " "Each table must be specified with both database and table names, e.g., " "--ignore-table-data=database.table.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"ignore-table", OPT_IGNORE_TABLE, "Do not dump the specified table. To specify more than one table to ignore, " "use the directive multiple times, once for each table. Each table must " "be specified with both database and table names, e.g., " "--ignore-table=database.table.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"include-master-host-port", 0, "Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' " "in dump produced with --dump-slave.", &opt_include_master_host_port,
&opt_include_master_host_port, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"insert-ignore", 0, "Insert rows with INSERT IGNORE.",
&opt_ignore, &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"lines-terminated-by", 0, "Lines in the output file are terminated by the given string.",
&lines_terminated, &lines_terminated, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"lock-all-tables", 'x', "Locks all tables across all databases. This " "is achieved by taking a global read lock for the duration of the whole " "dump. Automatically turns --single-transaction and --lock-tables off.",
&opt_lock_all_tables, &opt_lock_all_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"lock-tables", 'l', "Lock all tables for read.", &lock_tables,
&lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"log-error", 0, "Append warnings and errors to given file.",
&log_error_file, &log_error_file, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"log-queries", 0, "When restoring the dump, the server will, if logging turned on, log the queries to the general and slow query log.",
&opt_logging, &opt_logging, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"master-data", OPT_MASTER_DATA, "This causes the binary log position and filename to be appended to the " "output. If equal to 1, will print it as a CHANGE MASTER command; if equal" " to 2, that command will be prefixed with a comment symbol. " "This option will turn --lock-all-tables on, unless --single-transaction " "is specified too (on servers before MariaDB 5.3 this will still take a " "global read lock for a short time at the beginning of the dump; " "don't forget to read about --single-transaction below). In all cases, " "any action on logs will happen at the exact moment of the dump. " "Option automatically turns --lock-tables off.",
&opt_master_data, &opt_master_data, 0,
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
{"max_allowed_packet", 0, "The maximum packet length to send to or receive from server.",
&opt_max_allowed_packet, &opt_max_allowed_packet, 0,
GET_ULONG, REQUIRED_ARG, 1024LL*1024*1024, 4096,
(longlong) 2L*1024L*1024L*1024L, 0, 1024, 0},
{"max-statement-time", 0, "Max statement execution time. If unset, overrides server default with 0.",
&opt_max_statement_time, &opt_max_statement_time, 0, GET_DOUBLE,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"net_buffer_length", 0, "The buffer size for TCP/IP and socket communication.",
&opt_net_buffer_length, &opt_net_buffer_length, 0, GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, 0, 1024, 0},
{"no-autocommit", 0, "Wrap tables with autocommit/commit statements.",
&no_autocommit, &no_autocommit, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
{"no-create-db", 'n', "Suppress the CREATE DATABASE ... IF EXISTS statement that normally is " "output for each dumped database if --all-databases or --databases is " "given.",
&opt_create_db, &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-create-info", 't', "Don't write table creation info.",
&opt_no_create_info, &opt_no_create_info, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-data", 'd', "No row information.", &opt_no_data,
&opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-data-med", 0, "No row information for engines that " "Manage External Data (" MED_ENGINES ").", &opt_no_data_med,
&opt_no_data_med, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"no-set-names", 'N', "Same as --skip-set-charset.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"opt", OPT_OPTIMIZE, "Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"order-by-primary", 0, "Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
&opt_order_by_primary, &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"order-by-size", 0, "Dump tables in the order of their size, smaller first. Useful when using --single-transaction on tables which get truncated often. " "Dumping smaller tables first reduces chances of often truncated tables to get altered before being dumped.",
&opt_order_by_size, &opt_order_by_size, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p', "Password to use when connecting to server. If password is not given it's solicited on the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"parallel", 'j', "Number of dump table jobs executed in parallel (only with --tab option)",
&opt_parallel, &opt_parallel, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #ifdef _WIN32
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"port", 'P', "Port number to use for connection.", &opt_mysql_port,
&opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe).", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
&quick, &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"quote-names",'Q', "Quote table and column names with backticks (`).",
&opt_quoted, &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"replace", 0, "Use REPLACE INTO instead of INSERT INTO.", &opt_replace_into,
&opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"result-file", 'r', "Direct output to a given file. This option should be used in systems " "(e.g., DOS, Windows) that use carriage-return linefeed pairs (\\r\\n) " "to separate text lines. This option ensures that only a single newline " "is used.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"routines", 'R', "Dump stored routines (functions and procedures).",
&opt_routines, &opt_routines, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"set-charset", 0, "Add 'SET NAMES default_character_set' to the output.", &opt_set_charset,
&opt_set_charset, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, /* Notethatthecombination--single-transaction--master-data willgivebullet-proofbinlogpositiononlyifserver>=4.1.3.That'sthe old"FLUSHTABLESWITHREADLOCKdoesnotblockcommit"fixedbug.
*/
{"single-transaction", 0, "Creates a consistent snapshot by dumping all tables in a single " "transaction. Works ONLY for tables stored in storage engines which " "support multiversioning (currently only InnoDB does); the dump is NOT " "guaranteed to be consistent for other storage engines. " "While a --single-transaction dump is in process, to ensure a valid " "dump file (correct table contents and binary log position), no other " "connection should use the following statements: ALTER TABLE, DROP " "TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not " "isolated from them. Option automatically turns off --lock-tables.",
&opt_single_transaction, &opt_single_transaction, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip-opt", OPT_SKIP_OPTIMIZATION, "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"socket", 'S', "The socket file to use for connection.",
&opt_mysql_unix_port, &opt_mysql_unix_port, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #include <sslopt-longopts.h>
{"system", 0, "Dump system tables as portable SQL",
&opt_system, &opt_system, &opt_system_types, GET_SET, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"tab",'T', "Create tab-separated textfile for each table to given path. (Create .sql " "and .txt files.) NOTE: This only works if mysqldump is run on the same " "machine as the mysqld server.",
&path, &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"tables", OPT_TABLES, "Overrides option --databases (-B).", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"triggers", 0, "Dump triggers for each dumped table.",
&opt_dump_triggers, &opt_dump_triggers, 0, GET_BOOL,
NO_ARG, 1, 0, 0, 0, 0, 0},
{"tz-utc", 0, "Set connection time zone to UTC before commencing the dump and add " "SET TIME_ZONE=´+00:00´ to the top of the dump file.",
&opt_tz_utc, &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, #ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", ¤t_user,
¤t_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"verbose", 'v', "Print info about the various stages.",
&verbose, &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version",'V', "Output version information and exit.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"where", 'w', "Dump only selected records. Quotes are mandatory.",
&where, &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"plugin_dir", 0, "Directory for client-side plugins.",
&opt_plugin_dir, &opt_plugin_dir, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"default_auth", 0, "Default authentication client-side plugin to use.",
&opt_default_auth, &opt_default_auth, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"galera-info", 0, "Include galera info at the end of dump.",
&opt_galera_info, &opt_galera_info, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
if (!opt_logging)
fprintf(sql_file, "\n/*M!100101 SET LOCAL SQL_LOG_OFF=0, LOCAL LOG_SLOW_QUERY=0 */;");
if (opt_set_charset)
fprintf(sql_file, "\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" "\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;" "\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;" "\n/*!40101 SET NAMES %s */;\n",default_charset);
if (opt_tz_utc)
{
fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
}
if (!multi_file_output)
{ /* We don't need unique checks as the table is created just before */
fprintf(md_result_file, "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n");
fprintf(md_result_file, "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n");
}
fprintf(sql_file, "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='%s%s%s' */;\n" "/*M!100616 SET @OLD_NOTE_VERBOSITY=@@NOTE_VERBOSITY, NOTE_VERBOSITY=0 */;\n",
multi_file_output?"":"NO_AUTO_VALUE_ON_ZERO",
compatible_mode_normal_str[0]==0?"":",",
compatible_mode_normal_str);
}
check_io(sql_file);
}
} /* write_header */
staticvoid write_footer(FILE *sql_file)
{ if (opt_xml)
{
fputs("</mysqldump>\n", sql_file);
check_io(sql_file);
} elseif (!opt_compact)
{ if (opt_tz_utc)
fprintf(sql_file,"/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
fprintf(sql_file,"\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n"); if (!multi_file_output)
{
fprintf(md_result_file,"\ /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n"); if (!opt_no_create_info)
{
fprintf(md_result_file,"\ /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
}
} if (opt_set_charset)
fprintf(sql_file, "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n" "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n" "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
fprintf(sql_file, "/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */;\n");
fputs("\n", sql_file);
*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
*mysql_params->p_net_buffer_length= opt_net_buffer_length; if (debug_info_flag)
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO; if (debug_check_flag)
my_end_arg= MY_CHECK_ERROR;
if (opt_delayed)
opt_lock=0; /* Can't have lock with delayed */
if (path != 0 && opt_dir != 0)
{
fprintf(stderr, "%s: Options --tab and --dir are mutually exclusive\n",
my_progname_short); return(EX_USAGE);
}
multi_file_output= path != 0 || opt_dir != 0;
if (multi_file_output)
{ constchar *outdir= path ? path : opt_dir; int stat_err; struct stat st; if ((stat_err = stat(outdir, &st)) != 0 || (st.st_mode & S_IFDIR) == 0)
{
fprintf(stderr, "%s: Path '%s' specified by option '%s' %s\n",
my_progname_short, outdir, path ? "--tab" : "--dir",
stat_err?"does not exist":"is not a directory"); return(EX_CONSCHECK);
}
}
if (!multi_file_output && (enclosed || opt_enclosed || escaped || lines_terminated ||
fields_terminated))
{
fprintf(stderr, "%s: You must use option --tab or --dir with --fields-...\n", my_progname_short); return(EX_USAGE);
} if (!multi_file_output && opt_header)
{
fprintf(stderr, "%s: You must use option --tab or --dir with --header\n", my_progname_short); return(EX_USAGE);
}
/* We don't delete master logs if slave data option */ if (opt_slave_data)
{
opt_lock_all_tables= !opt_single_transaction;
opt_delete_master_logs= 0; if (opt_slave_data != MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL)
opt_master_data= 0;
}
/* Ensure consistency of the set of binlog & locking options */ if (opt_delete_master_logs && !opt_master_data)
opt_master_data= MYSQL_OPT_MASTER_DATA_COMMENTED_SQL; if (opt_single_transaction && opt_lock_all_tables)
{
fprintf(stderr, "%s: You can't use --single-transaction and " "--lock-all-tables at the same time.\n", my_progname_short); return(EX_USAGE);
} if (opt_master_data)
opt_lock_all_tables= !opt_single_transaction; if (opt_single_transaction || opt_lock_all_tables)
lock_tables= 0; if (enclosed && opt_enclosed)
{
fprintf(stderr, "%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n", my_progname_short); return(EX_USAGE);
} if ((opt_databases || opt_alldbs) && path)
{
fprintf(stderr, "%s: --databases or --all-databases can't be used with --tab.\n",
my_progname_short); return(EX_USAGE);
} if (ignore_database.records && !opt_alldbs && !(opt_wildcards && opt_databases))
{
fprintf(stderr, "%s: --ignore-database can only be used together with --all-databases" " or --wildcards --databases.\n",
my_progname_short); return(EX_USAGE);
} if (opt_xml && multi_file_output)
{
fprintf(stderr, "%s: --xml can't be used with --tab or --dir.\n", my_progname_short); return(EX_USAGE);
} if (opt_dump_history)
{ if (opt_update_history)
{ /* dump history requires timezone "+00:00" */
opt_tz_utc= 1;
} if (opt_xml)
{
fprintf(stderr, "%s: --xml can't be used with --dump-history.\n",
my_progname_short); return(EX_USAGE);
} if (opt_replace_into)
{
fprintf(stderr, "%s: --dump-history can't be used with --replace.\n",
my_progname_short); return(EX_USAGE);
} if (opt_asof_timestamp)
{
fprintf(stderr, "%s: --dump-history can't be used with --as-of.\n",
my_progname_short); return(EX_USAGE);
}
} if (opt_asof_timestamp && strchr(opt_asof_timestamp, '\''))
{
fprintf(stderr, "%s: Incorrect DATETIME value: '%s'\n",
my_progname_short, opt_asof_timestamp); return(EX_USAGE);
}
if (strcmp(default_charset, MYSQL_AUTODETECT_CHARSET_NAME) &&
!(charset_info= get_charset_by_csname(default_charset, MY_CS_PRIMARY,
MYF(MY_UTF8_IS_UTF8MB3 | MY_WME)))) exit(1); if (opt_order_by_size && (*argc > 1 && !opt_databases))
{
fprintf(stderr, "%s: --order-by-size can't be used when dumping selected tables\n",
my_progname_short); return EX_USAGE;
} if ((*argc < 1 && (!opt_alldbs && !opt_system)) || (*argc > 0 && opt_alldbs))
{
short_usage(stderr); return EX_USAGE;
} if (tty_password)
opt_password=my_get_tty_password(NullS); return(0);
} /* get_options */
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
MYSQL* con = mysql_init(NULL); if (opt_compress)
mysql_options(con,MYSQL_OPT_COMPRESS,NullS);
SET_SSL_OPTS_WITH_CHECK(con); if (opt_protocol)
mysql_options(con,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
mysql_options(con, MYSQL_SET_CHARSET_NAME, default_charset);
if (opt_plugin_dir && *opt_plugin_dir)
mysql_options(con, MYSQL_PLUGIN_DIR, opt_plugin_dir);
if (opt_default_auth && *opt_default_auth)
mysql_options(con, MYSQL_DEFAULT_AUTH, opt_default_auth);
mysql_options(con, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
mysql_options4(con, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name", "mysqldump"); if (!mysql_real_connect(con,host,user,passwd,
NULL,opt_mysql_port,opt_mysql_unix_port, 0))
{
DB_error(con, "when trying to connect"); goto err;
}
if ((mysql_get_server_version(con) < 40100) ||
(opt_compatible_mode & 3))
{ /* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
opt_set_charset= 0;
/* Don't switch charsets for 4.1 and earlier. (bug#34192). */
server_supports_switching_charsets= FALSE;
} /* Aswe'regoingtosetSQL_MODE,itwouldbelostonreconnect,sowe cannotreconnect.
*/
reconnect= 0;
mysql_options(con, MYSQL_OPT_RECONNECT, &reconnect);
my_snprintf(buff, sizeof(buff), "/*!40100 SET @@SQL_MODE='%s' */",
compatible_mode_normal_str); if (mysql_query_with_error_report(con, 0, buff)) goto err; /* settime_zonetoUTCtoallowdumpingdatetypesbetweenserverswith differenttimezonesettings
*/ if (opt_tz_utc)
{ if (mysql_query_with_error_report(con, 0, "/*!40103 SET TIME_ZONE='+00:00' */")) goto err;
}
/* Set MAX_STATEMENT_TIME to 0 unless set in client */
my_snprintf(buff, sizeof(buff), "/*M!100100 SET @@MAX_STATEMENT_TIME=%f */",
opt_max_statement_time); if (mysql_query_with_error_report(con, 0, buff)) goto err;
/* Set server side timeout between client commands to server compiled-in default */ if(mysql_query_with_error_report(con,0, "/*M!100100 SET WAIT_TIMEOUT=DEFAULT */")) goto err;
DBUG_RETURN(con);
err: if (con)
mysql_close(con);
DBUG_RETURN(NULL);
} /* connect_to_db */
if (mysql_num_fields(event_res) >= 7)
{
restore_cs_variables(sql_file);
if (db_cl_altered)
{ if (restore_db_collation(sql_file, db_name_buff, db_cl_name)) goto err;
}
}
}
} /* end of event printing */
mysql_free_result(event_res);
event_res= NULL;
} /* end of list of events */ if (opt_xml)
{
fputs("\t</events>\n", sql_file);
check_io(sql_file);
} else
{
fprintf(sql_file, "/*!50106 SET TIME_ZONE= @save_time_zone */ ;\n");
}
if (switch_character_set_results(mysql, default_charset)) goto err;
}
mysql_free_result(event_list_res);
if (lock_tables)
(void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES");
DBUG_RETURN(0);
if (fetch_db_collation(db, db_cl_name, sizeof (db_cl_name)))
DBUG_RETURN(1);
if (switch_character_set_results(mysql, "binary"))
DBUG_RETURN(1);
if (opt_xml)
fputs("\t<routines>\n", sql_file);
/* 0, retrieve and dump functions, 1, procedures, etc. */ for (i= 0; i < array_elements(routine_dump_param_array); i++)
{ const routine_dump_param_st *param= &routine_dump_param_array[i]; if (mysql_get_server_version(mysql) < param->version) continue;
my_snprintf(query_buff, sizeof(query_buff), "SHOW %s STATUS WHERE Db = '%s'",
param->routine_type, db_name_buff);
if (mysql_query_with_error_report(mysql, &routine_list_res, query_buff))
DBUG_RETURN(1);
// Restore next not cached value from sequence
my_snprintf(buff, sizeof(buff), "SELECT next_not_cached_value FROM %s", result_seq); if (mysql_query_with_error_report(mysql, &result, buff))
{
DBUG_VOID_RETURN;
}
row= mysql_fetch_row(result); if (row[0])
{
fprintf(sql_file, "DO SETVAL(%s, %s, 0);\n", result_seq, row[0]);
} // Sequences will not use inserts, so no need for REPLACE and LOCKS
mysql_free_result(result);
}
DBUG_VOID_RETURN;
} /* get_table_structure--retrievesdatabasestructure,printsoutcorresponding CREATEstatementandfillsoutinsert_patifthetableisthetypewewill bedumping.
if (!opt_copy_s3_tables && *ignore_flag == IGNORE_S3_TABLE)
DBUG_RETURN(-1);
delayed= opt_delayed; if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
{
delayed= 0;
verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' " "because it's of type %s\n", table, table_type);
}
if (opt_order_by_primary)
order_by= primary_key_fields(result_table);
if (!opt_xml)
{ int vers_hidden= opt_dump_history && *versioned; if (mysql_query_with_error_report(mysql, 0, query_buff))
DBUG_RETURN(-1); /* using SHOW CREATE statement */ if (!opt_no_create_info)
{ /* Make an sql-file, if path was given iow. option -T was given */ char buff[20+FN_REFLEN];
MYSQL_FIELD *field;
verbose_msg("-- It's a view, create dummy view for view\n");
/* save "show create" statement for later */ if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
scv_buff= my_strdup(PSI_NOT_INSTRUMENTED, scv_buff, MYF(0));
if (complete_insert)
dynstr_append_checked(&insert_pat, insert_field_names.str);
num_fields= field_flags.length; if (!num_fields)
dynstr_append_checked(&select_field_names, "0");
mysql_free_result(result);
} else
{ constchar *show_fields_stmt= "SELECT `COLUMN_NAME` AS `Field`, " "`COLUMN_TYPE` AS `Type`, " "`IS_NULLABLE` AS `Null`, " "`COLUMN_KEY` AS `Key`, " "`COLUMN_DEFAULT` AS `Default`, " "`EXTRA` AS `Extra`, " "`COLUMN_COMMENT` AS `Comment` " "FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE " "TABLE_SCHEMA = %s AND TABLE_NAME = %s " "ORDER BY ORDINAL_POSITION";
if (mysql_query_with_error_report(mysql, &result, query_buff))
DBUG_RETURN(-1);
/* Make an sql-file, if path was given iow. option -T was given */ if (!opt_no_create_info)
{
print_comment(sql_file, 0, "\n--\n-- Table structure for table %s\n--\n\n",
fix_for_comment(result_table));
print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table,
NullS);
check_io(sql_file);
}
while ((row= mysql_fetch_row(result)))
{
dynstr_append_mem_checked(&field_flags, "", 1); /* VECTOR doesn't have a type code yet, must be detected by name */ if (strncmp(row[SHOW_TYPE], STRING_WITH_LEN("vector(")) == 0)
field_flags.str[field_flags.length-1]|= MYSQL_TYPE_VECTOR; if (init)
dynstr_append_checked(&select_field_names, ", ");
dynstr_append_checked(&select_field_names,
quote_name(row[SHOW_FIELDNAME], name_buff, 0));
init=1;
if (!opt_no_create_info)
print_xml_row(sql_file, "field", result, &row, NullS);
}
num_fields= mysql_num_rows(result);
mysql_free_result(result); if (!opt_no_create_info)
{ char buff[20+FN_REFLEN];
my_snprintf(buff, sizeof(buff), "show keys from %s", result_table); if (mysql_query_with_error_report(mysql, &result, buff))
{ if (mysql_errno(mysql) == ER_WRONG_OBJECT)
{ /* it is VIEW */
fputs("\t\t<options Comment=\"view\" />\n", sql_file); goto continue_xml;
}
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
my_progname_short, result_table, mysql_error(mysql));
DBUG_RETURN(-1);
}
while ((row= mysql_fetch_row(result)))
print_xml_row(sql_file, "key", result, &row, NullS);
mysql_free_result(result);
/* Get MySQL specific create options */ if (create_options)
{ char show_name_buff[NAME_LEN*2+2+24];
/* Check memory for quote_for_like() */
my_snprintf(buff, sizeof(buff), "show table status like %s",
quote_for_like(table, show_name_buff));
if (mysql_query_with_error_report(mysql, &result, buff))
{ if (mysql_errno(mysql) != ER_PARSE_ERROR)
{ /* If old MySQL version */
verbose_msg("-- Warning: Couldn't get status information for " \ "table %s (%s)\n", result_table,mysql_error(mysql));
}
} elseif (!(row= mysql_fetch_row(result)))
{
fprintf(stderr, "Error: Couldn't read status information for table %s (%s)\n",
result_table,mysql_error(mysql));
} else
print_xml_row(sql_file, "options", result, &row, NullS);
mysql_free_result(result); /* Is always safe to free */
}
continue_xml:
fputs("\t</table_structure>\n", sql_file);
check_io(sql_file);
}
} if (complete_insert)
{
dynstr_append_checked(&insert_pat, ") VALUES "); if (!extended_insert)
dynstr_append_checked(&insert_pat, "(");
} if (sql_file != md_result_file)
{
fputs("\n", sql_file);
write_footer(sql_file);
my_fclose(sql_file, MYF(MY_WME));
}
DBUG_RETURN((uint) num_fields);
} /* get_table_structure */
char name_buff[NAME_LEN * 4 + 3]; constchar *xml_msg= "\nWarning! mysqldump being run against old server " "that does not\nsupport 'SHOW CREATE TRIGGER' " "statement. Skipping..\n";
DBUG_ENTER("dump_trigger_old");
if (opt_xml)
{
print_xml_comment(sql_file, strlen(xml_msg), xml_msg);
check_io(sql_file);
DBUG_VOID_RETURN;
}
fprintf(sql_file, "--\n" "-- WARNING: old server version. " "The following dump may be incomplete.\n" "--\n");
if (opt_compact)
fprintf(sql_file, "/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n");
if (opt_drop_trigger)
fprintf(sql_file, "/*!50032 DROP TRIGGER IF EXISTS %s */;\n",
quote_name((*show_trigger_row)[0], name_buff, 0));
char db_cl_name[MY_CS_COLLATION_NAME_SIZE]; int ret= TRUE; /* Servers below 5.1.21 do not support SHOW CREATE TRIGGER */ constint use_show_create_trigger= mysql_get_server_version(mysql) >= 50121;
done: if (multi_file_output)
my_fclose(sql_file, MYF(0));
mysql_free_result(show_triggers_rs);
DBUG_RETURN(ret);
}
staticvoid add_load_option(DYNAMIC_STRING *str, constchar *option, constchar *option_value)
{ if (!option_value)
{ /* Null value means we don't add this option. */ return;
}
staticvoid field_escape(DYNAMIC_STRING* in, constchar *from)
{
uint end_backslashes= 0;
dynstr_append_checked(in, "'");
while (*from)
{
dynstr_append_mem_checked(in, from, 1);
if (*from == '\\')
end_backslashes^=1; /* find odd number of backslashes */ else
{ if (*from == '\'' && !end_backslashes)
{ /* We want a duplicate of "'" for MySQL */
dynstr_append_checked(in, "\'");
}
end_backslashes=0;
}
from++;
} /* Add missing backslashes if user has specified odd number of backs.*/ if (end_backslashes)
dynstr_append_checked(in, "\\");
/* The"table"couldbeaview.Ifso,wedon'tdoanythinghere.
*/ if (strcmp(table_type, "VIEW") == 0)
DBUG_VOID_RETURN;
if (!opt_copy_s3_tables && (ignore_flag & IGNORE_S3_TABLE))
{
verbose_msg("-- Skipping dump data for table '%s', " " this is S3 table and --copy-s3-tables=0\n",
table);
DBUG_VOID_RETURN;
}
/* Check --no-data flag */ if (opt_no_data || (hash_key && ignore_table_data(hash_key, len)))
{
verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
table);
DBUG_VOID_RETURN;
}
DBUG_PRINT("info", ("ignore_flag: %x num_fields: %d", (int) ignore_flag,
num_fields)); /* Ifthetabletypeisamergetableoranytypethathastobe _completely_ignoredandnodatadumped
*/ if (ignore_flag & IGNORE_DATA)
{
verbose_msg("-- Warning: Skipping data for table '%s' because " \ "it's of type %s\n", table, table_type);
DBUG_VOID_RETURN;
}
/* Check--skip-eventsflag:itisnotenoughtoskipcreationofevents discardingSHOWCREATEEVENTstatementsgeneration.Themysql.event tabledatashouldbeskippedtoo.
*/ if (!opt_events && !cmp_database(db, "mysql") &&
!cmp_table(table, "event"))
{
verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
DBUG_VOID_RETURN;
}
add_load_option(&query_string, " TERMINATED BY ", fields_terminated);
add_load_option(&query_string, " ENCLOSED BY ", enclosed);
add_load_option(&query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
add_load_option(&query_string, " ESCAPED BY ", escaped);
add_load_option(&query_string, " LINES TERMINATED BY ", lines_terminated);
if (opt_header)
{
dynstr_append_checked(&query_string, " FROM ( SELECT "); if (order_by)
dynstr_append_checked(&query_string, " 0 AS `_$is_data_row$_`,");
dynstr_append_checked(&query_string, select_field_names_for_header.str);
dynstr_append_checked(&query_string, " UNION ALL SELECT "); if (order_by)
dynstr_append_checked(&query_string, "1 AS `_$is_data_row$_`,");
dynstr_append_checked(&query_string, select_field_names.str);
}
dynstr_append_checked(&query_string, " FROM "); char quoted_db_buf[NAME_LEN * 2 + 3]; char *qdatabase= quote_name(db, quoted_db_buf, opt_quoted);
dynstr_append_checked(&query_string, qdatabase);
dynstr_append_checked(&query_string, ".");
dynstr_append_checked(&query_string, result_table);
if (versioned)
vers_append_system_time(&query_string);
if (where)
{
dynstr_append_checked(&query_string, " WHERE ");
dynstr_append_checked(&query_string, where);
} if (opt_header)
dynstr_append_checked(&query_string, ") s");
if (order_by)
{ if (opt_header)
dynstr_append_checked(&query_string, " ORDER BY `_$is_data_row$_`,"); else
dynstr_append_checked(&query_string, " ORDER BY ");
dynstr_append_checked(&query_string, order_by);
my_free(order_by);
order_by= 0;
} if (opt_parallel)
{ if (connection_pool.execute_async(query_string.str,send_query_completion_func,nullptr,true))
{
dynstr_free(&query_string);
DB_error(mysql, "when executing send_query 'SELECT INTO OUTFILE'");
DBUG_VOID_RETURN;
}
} elseif (mysql_real_query(mysql, query_string.str, (ulong)query_string.length))
{
dynstr_free(&query_string);
DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
DBUG_VOID_RETURN;
}
} else
{
print_comment(md_result_file, 0, "\n--\n-- Dumping data for table %s\n--\n",
fix_for_comment(result_table));
dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ ");
dynstr_append_checked(&query_string, select_field_names.str);
dynstr_append_checked(&query_string, " FROM ");
dynstr_append_checked(&query_string, result_table); if (versioned)
vers_append_system_time(&query_string);
if (where)
{
print_comment(md_result_file, 0, "-- WHERE: %s\n", fix_for_comment(where));
dynstr_append_checked(&query_string, " WHERE ");
dynstr_append_checked(&query_string, where);
} if (order_by)
{
print_comment(md_result_file, 0, "-- ORDER BY: %s\n", fix_for_comment(order_by));
dynstr_append_checked(&query_string, " ORDER BY ");
dynstr_append_checked(&query_string, order_by);
my_free(order_by);
order_by= 0;
}
if (!opt_xml && !opt_compact)
{
fputs("\n", md_result_file);
check_io(md_result_file);
} if (mysql_query_with_error_report(mysql, 0, query_string.str))
{
dynstr_free(&query_string);
DB_error(mysql, "when retrieving data from server"); goto err;
} if (quick)
res=mysql_use_result(mysql); else
res=mysql_store_result(mysql); if (!res)
{
dynstr_free(&query_string);
DB_error(mysql, "when retrieving data from server"); goto err;
}
verbose_msg("-- Retrieving rows...\n"); if (num_fields && mysql_num_fields(res) != (uint)num_fields)
{
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
my_progname_short, result_table);
error= EX_CONSCHECK; if (!quick)
mysql_free_result(res); goto err;
}
if (versioned && !opt_xml && opt_dump_history)
{
fprintf(md_result_file,"/*M!101100 SET @old_system_versioning_insert_history=@@session.system_versioning_insert_history, @@session.system_versioning_insert_history=1 */;\n");
check_io(md_result_file);
} if (no_autocommit)
{
fprintf(md_result_file, "SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;\n");
check_io(md_result_file);
} if (opt_lock)
{
fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
check_io(md_result_file);
} /* Moved disable keys to after lock per bug 15977 */ if (opt_disable_keys)
{
fprintf(md_result_file, "/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
opt_quoted_table);
check_io(md_result_file);
}
total_length= opt_net_buffer_length; /* Force row break */
row_break=0;
rownr=0;
init_length=(uint) insert_pat.length+4; if (opt_xml)
print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
NullS);
while ((row= mysql_fetch_row(res)))
{
uint i;
ulong *lengths= mysql_fetch_lengths(res);
rownr++; if (!extended_insert && !opt_xml)
{
fputs(insert_pat.str,md_result_file);
check_io(md_result_file);
}
mysql_field_seek(res,0);
if (opt_xml)
{
fputs("\t<row>\n", md_result_file);
check_io(md_result_file);
} elseif (extended_insert)
dynstr_set_checked(&extended_row,"(");
for (i= 0; i < (uint)num_fields; i++)
{ int is_blob;
ulong length= lengths[i];
if (!(field= mysql_fetch_field(res)))
die(EX_CONSCHECK, "Not enough fields from table %s! Aborting.\n",
result_table);
staticint dump_all_users_roles_and_grants()
{
MYSQL_ROW row;
MYSQL_RES *tableres; int result= 0; /* Roles added in MariaDB-10.0.5 or MySQL-8.0 */
my_bool maria_roles_exist= (mysql_get_server_version(mysql) >= 100005);
my_bool mysql_roles_exist= (mysql_get_server_version(mysql) >= 80001) && !maria_roles_exist;
if (mysql_query_with_error_report(mysql, &tableres, "SELECT CONCAT(QUOTE(u.user), '@', QUOTE(u.Host)) AS u " "FROM mysql.user u " " /*!80001 LEFT JOIN mysql.role_edges e " " ON u.user=e.from_user " " AND u.host=e.from_host " " WHERE e.from_user IS NULL */" " /*M!100005 WHERE is_role='N' */")) return1; while ((row= mysql_fetch_row(tableres)))
{ char buf[200]; if (opt_replace_into) /* Protection against removing the current import user */ /* MySQL-8.0 export capability */
fprintf(md_result_file, "DELIMITER |\n" "/*M!100101 IF current_user()=%s THEN\n" " SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=30001," " MESSAGE_TEXT=\"Don't remove current user %s'\";\n" "END IF */|\n" "DELIMITER ;\n" "/*!50701 DROP USER IF EXISTS %s */;\n",
quote_for_equal(row[0],buf), row[0], row[0]); if (dump_create_user(row[0]))
result= 1; /* if roles exist, defer dumping grants until after roles created */ if (maria_roles_exist || mysql_roles_exist) continue; if (dump_grants(row[0]))
result= 1;
}
mysql_free_result(tableres);
if (!(maria_roles_exist || mysql_roles_exist)) gotoexit;
Attheendoftheimportthemariadb_dump_import_roleisbedropped, whichimplicitlydropsallitsadminaspectsofthedroppedrole. ThisissignificantlyeasierthanrevokingtheADMINofeachrole fromthecurrentuser.
*/
fputs("SELECT COALESCE(CURRENT_ROLE(),'NONE') into @current_role;\n" "CREATE ROLE IF NOT EXISTS mariadb_dump_import_role;\n" "GRANT mariadb_dump_import_role TO CURRENT_USER();\n" "SET ROLE mariadb_dump_import_role;\n"
, md_result_file); /* No show create role yet, MDEV-22311 */ /* Roles, with user admins first, then roles they administer, and recurse on that */ if (maria_roles_exist && mysql_query_with_error_report(mysql, &tableres, "WITH RECURSIVE create_role_order AS" " (SELECT 1 as n, roles_mapping.*" " FROM mysql.roles_mapping" " JOIN mysql.user USING (user,host)" " WHERE is_role='N'" " AND Admin_option='Y'" " UNION SELECT c.n+1, r.*" " FROM create_role_order c" " JOIN mysql.roles_mapping r ON c.role=r.user" " AND r.host=''" " AND r.Admin_option='Y') " "SELECT QUOTE(ROLE) AS r," " CONCAT(QUOTE(user)," " IF(HOST='', '', CONCAT('@', QUOTE(HOST)))) AS c," " Admin_option " "FROM create_role_order ORDER BY n, r, user")) return1; /* TODOMysql-missesrolesthathavenoadminorrolemembers. MySQLrolesdon'trequireanadmin.
*/ if (mysql_roles_exist && mysql_query_with_error_report(mysql, &tableres, "WITH RECURSIVE create_role_order AS" " (SELECT 1 AS n," " re.*" " FROM mysql.role_edges re" " JOIN mysql.user u ON re.TO_HOST=u.HOST" " AND re.TO_USER = u.USER" " LEFT JOIN mysql.role_edges re2 ON re.TO_USER=re2.FROM_USER" " AND re2.TO_HOST=re2.FROM_HOST" " WHERE re2.FROM_USER IS NULL" " UNION SELECT c.n+1," " re.*" " FROM create_role_order c" " JOIN mysql.role_edges re ON c.FROM_USER=re.TO_USER" " AND c.FROM_HOST=re.TO_HOST) " "SELECT CONCAT(QUOTE(FROM_USER), '/*!80001 @', QUOTE(FROM_HOST), '*/') AS r," " CONCAT(QUOTE(TO_USER), IF(n=1, CONCAT('@', QUOTE(TO_HOST))," " CONCAT('/*!80001 @', QUOTE(TO_HOST), ' */'))) AS u," " WITH_ADMIN_OPTION " "FROM create_role_order " "ORDER BY n," " FROM_USER," " FROM_HOST," " TO_USER," " TO_HOST," " WITH_ADMIN_OPTION")) return1; while ((row= mysql_fetch_row(tableres)))
{ /* MySQL-8.0 export capability */ if (opt_replace_into)
fprintf(md_result_file, "/*!80001 DROP ROLE IF EXISTS %s */;\n", row[0]);
fprintf(md_result_file, "/*!80001 CREATE ROLE %s%s */;\n", opt_ignore ? "IF NOT EXISTS " : "", row[0]); /* By default created with current role */
fprintf(md_result_file, "%sROLE %s%s WITH ADMIN mariadb_dump_import_role */;\n",
opt_replace_into ? "/*M!100103 CREATE OR REPLACE ": "/*M!100005 CREATE ",
opt_ignore ? "IF NOT EXISTS " : "", row[0]);
fprintf(md_result_file, "/*M!100005 GRANT %s TO %s%s*/;\n",
row[0], row[1], (row[2][0] == 'Y') ? " WITH ADMIN OPTION " : "");
}
mysql_free_result(tableres);
/* users and their default role */ if (maria_roles_exist && mysql_query_with_error_report(mysql, &tableres, "select IF(default_role='', 'NONE', QUOTE(default_role)) as r," "concat(QUOTE(User), '@', QUOTE(Host)) as u FROM mysql.user " "/*M!100005 WHERE is_role='N' */")) return1; if (mysql_roles_exist && mysql_query_with_error_report(mysql, &tableres, "SELECT IF(DEFAULT_ROLE_HOST IS NULL, 'NONE', CONCAT(QUOTE(DEFAULT_ROLE_USER)," " '@', QUOTE(DEFAULT_ROLE_HOST))) as r," " CONCAT(QUOTE(mu.USER),'@',QUOTE(mu.HOST)) as u " "FROM mysql.user mu LEFT JOIN mysql.default_roles using (USER, HOST)"))
{
mysql_free_result(tableres); return1;
}
while ((row= mysql_fetch_row(tableres)))
{ if (dump_grants(row[1]))
result= 1;
fprintf(md_result_file, "/*M!100005 SET DEFAULT ROLE %s FOR %s */;\n", row[0], row[1]);
fprintf(md_result_file, "/*!80001 ALTER USER %s DEFAULT ROLE %s */;\n", row[1], row[0]);
}
mysql_free_result(tableres);
if (maria_roles_exist && mysql_query_with_error_report(mysql, &tableres, "SELECT DISTINCT QUOTE(m.role) AS r " " FROM mysql.roles_mapping m" " JOIN mysql.user u ON u.user = m.role" " WHERE is_role='Y'" " AND Admin_option='Y'" " ORDER BY m.role")) return1; if (mysql_roles_exist && mysql_query_with_error_report(mysql, &tableres, "SELECT DISTINCT CONCAT(QUOTE(FROM_USER),'@', QUOTE(FROM_HOST)) AS r " "FROM mysql.role_edges")) return1; while ((row= mysql_fetch_row(tableres)))
{ if (dump_grants(row[0]))
result= 1;
}
mysql_free_result(tableres); /* switch back */
fputs("SET ROLE NONE;\n" "DROP ROLE mariadb_dump_import_role;\n" "/*M!100203 EXECUTE IMMEDIATE CONCAT('SET ROLE ', @current_role) */;\n",
md_result_file); exit:
if (mysql_query_with_error_report(mysql, &tableres, "SHOW PLUGINS")) return1; /* Name, Status, Type, Library, License */ while ((row= mysql_fetch_row(tableres)))
{ char name_buff[NAME_LEN*2+3]; if (strcmp("ACTIVE", row[1]) != 0) continue; /* Should we be skipping builtins? */ if (row[3] == NULL) continue; if (opt_replace_into)
{
fprintf(md_result_file, "/*M!100401 UNINSTALL PLUGIN IF EXIST %s */;\n",
quote_name(row[0], name_buff, 0));
}
fprintf(md_result_file, "INSTALL PLUGIN %s %s SONAME ",
quote_name(row[0], name_buff, 0),
opt_ignore ? "/*M!100401 IF NOT EXISTS */" : "");
unescape(md_result_file, row[3], strlen(row[3]));
fputs(";\n", md_result_file);
check_io(md_result_file);
}
mysql_free_result(tableres);
return0;
}
/* dumpalludfs
*/
staticint dump_all_udfs()
{ /* we don't support all these types yet, but get prepared if we do */ staticconstchar *udf_types[] = {"STRING", "REAL", "INT", "ROW", "DECIMAL", "TIME" };
MYSQL_ROW row;
MYSQL_RES *tableres; int retresult, result= 0;
if (mysql_query_with_error_report(mysql, &tableres, "SELECT * FROM mysql.func")) return1; /* Name, ret, dl, type*/ while ((row= mysql_fetch_row(tableres)))
{ char name_buff[NAME_LEN*2+3];
retresult= atoi(row[1]); if (retresult < 0 || array_elements(udf_types) <= (size_t) retresult)
{
fprintf(stderr, "%s: Error: invalid return type on udf function '%s'\n",
my_progname_short, row[0]);
result= 1; continue;
} if (opt_replace_into)
{
fprintf(md_result_file, "/*!50701 DROP FUNCTION IF EXISTS %s */;\n",
quote_name(row[0], name_buff, 0));
}
fprintf(md_result_file, "CREATE %s%sFUNCTION %s%s RETURNS %s SONAME ",
opt_replace_into ? "/*M!100103 OR REPLACE */ ": "",
(strcmp("aggregate", row[3])==0 ? "AGGREGATE " : ""),
opt_ignore ? "IF NOT EXISTS " : "",
quote_name(row[0], name_buff, 0), udf_types[retresult]);
unescape(md_result_file, row[2], strlen(row[2]));
fputs(";\n", md_result_file);
check_io(md_result_file);
}
mysql_free_result(tableres);
init_dynamic_string_checked(&sqlbuf, "SELECT LOGFILE_GROUP_NAME," " FILE_NAME," " TOTAL_EXTENTS," " INITIAL_SIZE," " ENGINE," " EXTRA" " FROM INFORMATION_SCHEMA.FILES" " WHERE FILE_TYPE = 'UNDO LOG'" " AND FILE_NAME IS NOT NULL" " AND LOGFILE_GROUP_NAME IS NOT NULL", 256, 1024); if(ts_where)
{
dynstr_append_checked(&sqlbuf, " AND LOGFILE_GROUP_NAME IN (" "SELECT DISTINCT LOGFILE_GROUP_NAME" " FROM INFORMATION_SCHEMA.FILES" " WHERE FILE_TYPE = 'DATAFILE'"
);
dynstr_append_checked(&sqlbuf, ts_where);
dynstr_append_checked(&sqlbuf, ")");
}
dynstr_append_checked(&sqlbuf, " GROUP BY LOGFILE_GROUP_NAME, FILE_NAME" ", ENGINE, TOTAL_EXTENTS, INITIAL_SIZE" " ORDER BY LOGFILE_GROUP_NAME");
if (mysql_query(mysql, sqlbuf.str) ||
!(tableres = mysql_store_result(mysql)))
{
dynstr_free(&sqlbuf); if (mysql_errno(mysql) == ER_BAD_TABLE_ERROR ||
mysql_errno(mysql) == ER_BAD_DB_ERROR ||
mysql_errno(mysql) == ER_UNKNOWN_TABLE)
{
fprintf(md_result_file, "\n--\n-- Not dumping tablespaces as no INFORMATION_SCHEMA.FILES" " table on this server\n--\n");
check_io(md_result_file);
DBUG_RETURN(0);
}
fprintf(stderr, "%s: Error: '%s' when trying to dump tablespaces\n",
my_progname_short, mysql_error(mysql));
DBUG_RETURN(1);
}
buf[0]= 0; while ((row= mysql_fetch_row(tableres)))
{ if (strcmp(buf, row[0]) != 0)
first= 1; if (first)
{
print_comment(md_result_file, 0, "\n--\n-- Logfile group: %s\n--\n",
fix_for_comment(row[0]));
/* Return 1 if we should copy the database */ static my_bool include_database(constchar *hash_key)
{ return !my_hash_search(&ignore_database, (uchar*) hash_key, strlen(hash_key));
}
/* check database name if it's INFORMATION_SCHEMA or PERFORMANCE_SCHEMA. */ staticbool is_IS_or_PS(constchar *schema_name)
{ if (mysql_get_server_version(mysql) >= FIRST_INFORMATION_SCHEMA_VERSION &&
!cmp_database(schema_name, INFORMATION_SCHEMA_DB_NAME)) returnTRUE;
if (mysql_get_server_version(mysql) >= FIRST_PERFORMANCE_SCHEMA_VERSION &&
!cmp_database(schema_name, PERFORMANCE_SCHEMA_DB_NAME)) returnTRUE;
returnFALSE;
}
/* check database name if it's SYS_SCHEMA. */ staticbool is_SyS(constchar *schema_name)
{ return (mysql_get_server_version(mysql) >= FIRST_SYS_SCHEMA_VERSION &&
!cmp_database(schema_name, SYS_SCHEMA_DB_NAME));
}
staticint dump_all_databases()
{
MYSQL_ROW row;
MYSQL_RES *tableres; int result=0;
if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES")) return1; while ((row= mysql_fetch_row(tableres)))
{ if (is_IS_or_PS(row[0]) || is_SyS(row[0])) continue;
if (include_database(row[0])) if (dump_all_tables_in_db(row[0]))
result=1;
}
mysql_free_result(tableres); if (seen_views)
{ if (mysql_query(mysql, "SHOW DATABASES") ||
!(tableres= mysql_store_result(mysql)))
{
fprintf(stderr, "%s: Error: Couldn't execute 'SHOW DATABASES': %s\n",
my_progname_short, mysql_error(mysql)); return1;
} while ((row= mysql_fetch_row(tableres)))
{ if (is_IS_or_PS(row[0]) || is_SyS(row[0])) continue;
if (include_database(row[0])) if (dump_all_views_in_db(row[0]))
result=1;
}
mysql_free_result(tableres);
} return result;
} /* dump_all_databases */
staticint dump_databases(char **db_names)
{ int result=0; char **db;
DBUG_ENTER("dump_databases");
for (db= db_names ; *db ; db++)
{ if (dump_all_tables_in_db(*db))
result=1;
} if (!result && seen_views)
{ for (db= db_names ; *db ; db++)
{ if (dump_all_views_in_db(*db))
result=1;
}
}
DBUG_RETURN(result);
} /* dump_databases */
if (opt_drop_database)
fprintf(md_result_file, "\n/*!50106 SET @save_log_output=@@LOG_OUTPUT*/;\n" "/*M!100203 EXECUTE IMMEDIATE IF(@@LOG_OUTPUT='TABLE' AND (@@LOG_SLOW_QUERY=1 OR @@GENERAL_LOG=1)," "\"SET GLOBAL LOG_OUTPUT='NONE'\", \"DO0\") */;\n");
if (get_table_structure("general_log",
database, table_type, &ignore_flag, NULL) <= 0)
verbose_msg("-- Warning: get_table_structure() failed with some internal " "error for 'general_log' table\n"); if (get_table_structure("slow_log",
database, table_type, &ignore_flag, NULL) <= 0)
verbose_msg("-- Warning: get_table_structure() failed with some internal " "error for 'slow_log' table\n"); /* general and slow query logs exist now */ if (opt_drop_database)
fprintf(md_result_file, "\n/*!50106 SET GLOBAL LOG_OUTPUT=@save_log_output*/;\n\n");
DBUG_VOID_RETURN;
}
RETURN 0casesensitive. >0caseinsensitive
*/ staticint get_sys_var_lower_case_table_names()
{ int lower_case_table_names = 0;
MYSQL_RES *table_res;
MYSQL_ROW row; constchar *show_var_query = "SHOW VARIABLES LIKE 'lower_case_table_names'"; if (mysql_query_with_error_report(mysql, &table_res, show_var_query)) return0; /* In case of error, assume default value of 0 */
if ((row= mysql_fetch_row(table_res)))
{
lower_case_table_names= atoi(row[1]);
mysql_free_result(table_res);
} if (!row)
mysql_free_result(table_res); return lower_case_table_names;
}
staticint dump_selected_tables(char *db, char **table_names, int tables)
{ char table_buff[NAME_LEN*2+3], table_type[NAME_LEN];
DYNAMIC_STRING lock_tables_query; char **dump_tables, **pos, **end; int lower_case_table_names;
DBUG_ENTER("dump_selected_tables");
if (init_dumping(db, init_dumping_tables))
DBUG_RETURN(1);
/* Figure out how to compare table names. */
lower_case_table_names = get_sys_var_lower_case_table_names();
init_dynamic_string_checked(&lock_tables_query, "LOCK TABLES ", 256, 1024); for (; tables > 0 ; tables-- , table_names++)
{ /* the table name passed on commandline may be wrong case */ if ((*pos= get_actual_table_name(*table_names, lower_case_table_names,
&glob_root)))
{ /* Add found table name to lock_tables_query */ if (lock_tables)
{
dynstr_append_checked(&lock_tables_query, quote_name(*pos, table_buff, 1));
dynstr_append_checked(&lock_tables_query, " READ /*!32311 LOCAL */,");
}
pos++;
} else
{ if (!ignore_errors)
{
dynstr_free(&lock_tables_query);
free_root(&glob_root, MYF(0));
}
maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names); /* We shall continue here, if --force was given */
}
}
end= pos;
/* Can't LOCK TABLES in I_S / P_S, so don't try. */ if (lock_tables && !is_IS_or_PS(db))
{ if (mysql_real_query(mysql, lock_tables_query.str,
(ulong)lock_tables_query.length-1))
{ if (!ignore_errors)
{
dynstr_free(&lock_tables_query);
free_root(&glob_root, MYF(0));
}
DB_error(mysql, "when doing LOCK TABLES"); /* We shall continue here, if --force was given */
}
}
dynstr_free(&lock_tables_query); if (flush_logs)
{ if (mysql_refresh(mysql, REFRESH_LOG))
{ if (!ignore_errors)
free_root(&glob_root, MYF(0));
DB_error(mysql, "when doing refresh");
} /* We shall continue here, if --force was given */ else
verbose_msg("-- dump_selected_tables : logs flushed successfully!\n");
} if (opt_xml)
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
/* obtain dump of routines (procs/functions) */ if (opt_routines && mysql_get_server_version(mysql) >= 50009)
{
DBUG_PRINT("info", ("Dumping routines for database %s", db));
dump_routines_for_db(db);
}
row= mysql_fetch_row(master); if (row && row[0] && row[1])
{
file= row[0];
offset= row[1];
} else
{
mysql_free_result(master); if (!ignore_errors)
{ /* SHOW MASTER STATUS reports nothing and --force is not enabled */
fprintf(stderr, "%s: Error: Binlogging on server not active\n",
my_progname_short);
maybe_exit(EX_MYSQLERR); return1;
} else
{ return0;
}
}
if (have_mariadb_gtid && get_gtid_pos(gtid_pos, 1))
{
mysql_free_result(master); return1;
}
}
/* gtid */ if (have_mariadb_gtid)
{ if (use_gtid)
{
fprintf(md_result_file, "%sCHANGE MASTER TO MASTER_USE_GTID=slave_pos;\n",
comment_prefix); /* When--gtidisspecifieddeferprintofSETgtid_slave_posuntil afteritsplaceholdertableisguaranteedtohavebeendumped.
*/
print_comment(md_result_file, 0, "\n-- A corresponding to the above master-data " "CHANGE-MASTER settings to the slave gtid state is printed " "later in the file.\n");
}
snprintf(set_gtid_pos, set_gtid_pos_size, fmt_gtid_pos,
(!use_gtid ? "-- " : comment_prefix), gtid_pos);
}
/* SHOW MASTER STATUS reports file and position */
print_comment(md_result_file, 0, "\n--\n-- Alternately, following is the position of the binary " "logging from SHOW MASTER STATUS at point of backup." "\n-- Use this when creating a slave of the master server " "where the backup was made." "\n-- The new server will be connecting to the master server " "where the backup was taken." "\n--\n\n");
fprintf(md_result_file, "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n",
(use_gtid ? "-- " : comment_prefix), file, offset); if (have_mariadb_gtid && !use_gtid)
print_comment(md_result_file, 0, "\n-- A corresponding to the above master-data CHANGE-MASTER " "settings to the slave gtid state is printed as comments " "later in the file.\n");
check_io(md_result_file);
if (!consistent_binlog_pos)
mysql_free_result(master);
return0;
}
staticint do_stop_slave_sql(MYSQL *mysql_con)
{
MYSQL_ROW row; // do_stop_slave_sql() should only be called once
DBUG_ASSERT(!slave_status_res);
// 11.6 and above switch (mysql_query_with_error_report(mysql_con, &slave_status_res, "SELECT Connection_name FROM information_schema.SLAVE_STATUS" // If the slave's SQL thread is not running, we don't stop (or start) it. " WHERE Slave_SQL_Running <> 'No'", true
)) { default: // placing `default` at top and `-1` at bottom for readable chaining return1; case0:
have_info_schema_slave_status= true;
slave_status_indices= {0, /* unused */ -1, // these are actually for the separate query in do_show_slave_status() 1, 2, 3, 4}; break; case -1:
have_info_schema_slave_status= false; // Between 10.0 and 11.5 inclusive switch (mysql_query_with_error_report(mysql_con, &slave_status_res, "SHOW ALL SLAVES STATUS", true
)) { default: return1; case0:
slave_status_indices= {0, 13, 3, 5, 11, 23}; break; case -1: // MySQL 8.0.22 and above if (mysql_query_with_error_report(mysql_con, &slave_status_res, "SHOW REPLICA STATUS"
)) return1;
slave_status_indices= {55, 11, 1, 3, 9, 21};
}
}
// Loop over all slaves while ((row= mysql_fetch_row(slave_status_res)))
{ if ((have_info_schema_slave_status ||
strcmp(row[slave_status_indices.slave_sql_running], "No")))
{ char query[39 + NAME_CHAR_LEN]; // sizeof(snprintf) if (likely(have_for_channel))
{ // 10.7+ or MySQL
snprintf(query, sizeof(query), "STOP REPLICA SQL_THREAD FOR CHANNEL '%.*s'",
NAME_CHAR_LEN, row[slave_status_indices.connection_name]); switch (mysql_query_with_error_report(mysql_con, nullptr, query, true)) { default: return1; case0: continue; case -1:; // fall-through to `!have_for_channel`
}
} // Between 10.0 and 10.6 inclusive
have_for_channel= false;
snprintf(query, sizeof(query), "STOP SLAVE '%.*s' SQL_THREAD",
NAME_CHAR_LEN, row[slave_status_indices.connection_name]); if (mysql_query_with_error_report(mysql_con, nullptr, query)) return1;
}
} return(0);
}
staticint add_stop_slave(void)
{ if (opt_comments)
fprintf(md_result_file, "\n--\n-- stop slave statement to make a recovery dump)\n--\n\n");
fprintf(md_result_file, "STOP ALL SLAVES;\n"); return(0);
}
staticint add_slave_statements(void)
{ if (opt_comments)
fprintf(md_result_file, "\n--\n-- start slave statement to make a recovery dump)\n--\n\n");
fprintf(md_result_file, "START ALL SLAVES;\n"); return(0);
}
if (have_info_schema_slave_status)
{ if (mysql_query_with_error_report(mysql_con, &slave, "SELECT Connection_name, Master_Host, Master_Port, Relay_Master_Log_File," " Exec_Master_Log_Pos FROM information_schema.SLAVE_STATUS"
))
{ if (!ignore_errors) // Query fails and --force is not enabled
fprintf(stderr, "%s: Error: Slave not set up\n", my_progname_short);
mysql_free_result(slave); return1;
}
} else
{ // Reuse the SHOW ALL SLAVES STATUS results from do_stop_slave_sql()
mysql_data_seek(slave_status_res, 0);
slave= slave_status_res;
}
if (have_mariadb_gtid)
{ char gtid_pos[MAX_GTID_LENGTH]; if (get_gtid_pos(gtid_pos, false))
{ if (have_info_schema_slave_status)
mysql_free_result(slave); return1;
}
snprintf(set_gtid_pos, set_gtid_pos_size,
fmt_gtid_pos, gtid_comment_prefix, gtid_pos);
}
print_comment(md_result_file, 0, "\n-- The following is the replication SQL position " "taken from SHOW SLAVE STATUS at the time of backup.\n" "-- Use this position when creating a clone or replacement " "server from where the backup was taken." "\n-- This new server will connects to the same master server(s).\n--\n" // defer print similarly to do_show_master_status() "-- The slave GTID position corresponding to the below " "CHANGE-MASTER settings is printed later in the file.\n"
); if (use_gtid)
print_comment(md_result_file, 0, "-- Use only the MASTER_USE_GTID=slave_pos or " "MASTER_LOG_FILE/MASTER_LOG_POS in the statements below." "\n\n");
while ((row= mysql_fetch_row(slave)))
{ if (use_gtid)
fprintf(md_result_file, "%sCHANGE MASTER %s TO MASTER_USE_GTID=slave_pos;\n",
gtid_comment_prefix,
quote_for_equal(row[slave_status_indices.connection_name], name_buff));
fprintf(md_result_file, "%sCHANGE MASTER %s TO ",
nogtid_comment_prefix,
quote_for_equal(row[slave_status_indices.connection_name], name_buff)); if (opt_include_master_host_port)
fprintf(md_result_file, "MASTER_HOST=%s, MASTER_PORT=%llu, ",
quote_for_equal(row[slave_status_indices.master_host], name_buff),
atoll(row[slave_status_indices.master_port]));
fprintf(md_result_file, "MASTER_LOG_FILE=%s, MASTER_LOG_POS=%llu;\n",
quote_for_equal(row[slave_status_indices.relay_master_log_file],
name_buff),
atoll(row[slave_status_indices.exec_master_log_pos]));
check_io(md_result_file);
}
if (have_info_schema_slave_status)
mysql_free_result(slave);
fprintf(md_result_file, "\n"); return0;
}
staticint do_start_slave_sql(MYSQL *mysql_con)
{
MYSQL_ROW row; int error= 0;
DBUG_ENTER("do_start_slave_sql");
Wewantthefirstconsistentreadtobeusedforalltablestodumpsowe needtheREPEATABLEREADlevel(notanythinglower,forexampleREAD COMMITTEDwouldgiveonenewconsistentreadperdumpedtable).
*/ if ((mysql_get_server_version(mysql_con) < 40100) && opt_master_data)
{
fprintf(stderr, "-- %s: the combination of --single-transaction and " "--master-data requires a MariaDB server version of at least 4.1 " "(current server's version is %s). %s\n",
ignore_errors ? "Warning" : "Error",
mysql_con->server_version ? mysql_con->server_version : "unknown",
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting."); if (!ignore_errors) exit(EX_MYSQLERR);
}
my_snprintf(show_keys_buff, sizeof(show_keys_buff), "SHOW KEYS FROM %s", table_name); if (mysql_query(mysql, show_keys_buff) ||
!(res= mysql_store_result(mysql)))
{
fprintf(stderr, "Warning: Couldn't read keys from table %s;" " records are NOT sorted (%s)\n",
table_name, mysql_error(mysql)); /* Don't exit, because it's better to print out unsorted records */ goto cleanup;
}
/* *FigureoutthelengthoftheORDERBYclauseresult. *NotethatSHOWKEYSisordered:aPRIMARYkeyisalwaysthefirst *row,andUNIQUEkeyscomebeforeothers.Soweonlyneedtocheck *thefirstkey,notallkeys.
*/ if ((row= mysql_fetch_row(res)) && atoi(row[1]) == 0)
{ /* Key is unique */ do
{
quoted_field= quote_name(row[4], buff, 0);
result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
} while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
}
/* Build the ORDER BY clause result */ if (result_length)
{ char *end; /* result (terminating \0 is already in result_length) */
result= (char *)my_malloc(PSI_NOT_INSTRUMENTED, result_length + 10, MYF(MY_WME)); if (!result)
{
fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n"); goto cleanup;
}
mysql_data_seek(res, 0);
row= mysql_fetch_row(res);
quoted_field= quote_name(row[4], buff, 0);
end= strmov(result, quoted_field); while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1)
{
quoted_field= quote_name(row[4], buff, 0);
end= strxmov(end, ",", quoted_field, NullS);
}
}
if (mysql_query_with_error_report(mysql, &table_res, query))
{
switch_character_set_results(mysql, default_charset);
DBUG_RETURN(0);
}
/* Check if this is a view */
field= mysql_fetch_field_direct(table_res, 0); if (strcmp(field->name, "View") != 0)
{
mysql_free_result(table_res);
switch_character_set_results(mysql, default_charset);
verbose_msg("-- It's base table, skipped\n");
DBUG_RETURN(0);
}
/* If requested, open separate .sql file for this view */ if (multi_file_output)
{ if (!(sql_file= open_sql_file_for_table(db, table, O_WRONLY)))
{
mysql_free_result(table_res);
DBUG_RETURN(1);
}
write_header(sql_file, db);
}
print_comment(sql_file, 0, "\n--\n-- Final view structure for view %s\n--\n\n",
fix_for_comment(result_table));
/* View might not exist if this view was dumped with --tab. */
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", opt_quoted_table);
/* Save the result of SHOW CREATE TABLE in ds_view */
row= mysql_fetch_row(table_res);
lengths= mysql_fetch_lengths(table_res);
init_dynamic_string_checked(&ds_view, row[1], lengths[1] + 1, 1024);
mysql_free_result(table_res);
/* Get the result from "select ... information_schema" */ if (!(table_res= mysql_store_result(mysql)) ||
!(row= mysql_fetch_row(table_res)))
{ if (table_res)
mysql_free_result(table_res);
dynstr_free(&ds_view);
DB_error(mysql, "when trying to save the result of SHOW CREATE TABLE in ds_view.");
DBUG_RETURN(1);
}
/* If a separate .sql file was opened, close it now */ if (sql_file != md_result_file)
{
fputs("\n", sql_file);
write_footer(sql_file);
my_fclose(sql_file, MYF(MY_WME));
}
DBUG_RETURN(0);
}
staticbool first_time= true; if (first_time)
{ /* Find out permissions and ownership of output directory */
first_time= false; if (stat(opt_dir, &st_out_dir) != 0)
{
die(EX_CONSCHECK, "Error: cannot stat output directory %s, errno %d",
opt_dir, errno);
}
}
/* Change permissions to be the same as for the output directory*/ if (fix_perms &&
chmod(dirpath, st_out_dir.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)))
{
fprintf(stderr, "Warning: cannot set permissions on directory %s, errno %d\n",
dirpath, errno);
fix_perms= false;
}
/* Changeownershiptobethesameasbackuprootdir. Ifusercan'tbechanged,trychangingownergrouponly.
*/ if (fix_ownership_uid &&
chown(dirpath, st_out_dir.st_uid, st_out_dir.st_gid))
{ // No warning, error is expected, unless current user is root.
fix_ownership_uid= false;
fix_ownership_gid= true;
}
if (fix_ownership_gid && chown(dirpath, -1, st_out_dir.st_gid))
{ if (!(st_out_dir.st_mode & S_IWOTH))
{ /* Only warn if directory is not world-writable (group ownership
matters more in this case), to avoid spamming stderr.*/
fprintf(stderr, "Warning: cannot set group ownership on directory %s, errno %d\n",
dirpath, errno);
}
fix_ownership_gid= false;
} #endif
}
/* If--diroptionisinuse,ensurethatoutputdirectoryforgivendb exists.
*/ staticvoid ensure_out_dir_exists(constchar *db)
{
DBUG_ASSERT(opt_dir); char outdir[FN_REFLEN];
format_fs_safe_output_dir(db, outdir, sizeof(outdir)); struct stat st; if (stat(outdir, &st) == 0)
{ if (st.st_mode & S_IFDIR) return;
die(EX_CONSCHECK, "Error: path '%s' exists, but it is not a directory",
outdir);
} if (my_mkdir(outdir, 0777, MYF(MY_WME)))
die(EX_MYSQLERR, "Error creating directory %s", outdir);
fix_permissions_and_owner(outdir);
}
mysql= connect_to_db(current_host, current_user, opt_password); if (!mysql)
{
free_resources(); exit(EX_MYSQLERR);
} if (!multi_file_output)
{
write_header(md_result_file, *argv); if (opt_parallel)
{
verbose_msg("-- Warning: ignoring --parallel setting, it currently only " "works together with --tab\n");
opt_parallel= 0;
}
} elseif (opt_parallel)
init_connection_pool(opt_parallel);
/* Check if the server support multi source */
have_mariadb_gtid= mysql_get_server_version(mysql) >= 100000;
if (opt_slave_data && do_stop_slave_sql(mysql)) goto err;
if (opt_single_transaction && opt_master_data)
{ /* See if we can avoid FLUSH TABLES WITH READ LOCK (MariaDB 5.3+). */
consistent_binlog_pos= check_consistent_binlog_pos(NULL, NULL);
}
/* Flushlogsbeforestartingtransactionsince thiscausesimplicitcommitstartingmysql-5.5.
*/ if (opt_lock_all_tables || opt_master_data ||
(opt_single_transaction && flush_logs) ||
opt_delete_master_logs)
{ if (flush_logs || opt_delete_master_logs)
{ if (mysql_refresh(mysql, REFRESH_LOG))
{
fprintf(stderr, "Flush logs or delete master logs failure in server \n");
first_error= EX_MYSQLERR; goto err;
}
verbose_msg("-- main : logs flushed successfully!\n");
}
/* Not anymore! That would not be sensible. */
flush_logs= 0;
}
if (opt_delete_master_logs)
{ if (get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name))) goto err;
}
if (opt_single_transaction)
{ if (start_transaction(mysql)) goto err;
connection_pool.for_each_connection([](MYSQL *c) { if (start_transaction(c))
maybe_die(EX_MYSQLERR, "Failed to start transaction on connection ID %lu", mysql->thread_id);
});
}
/* Add 'STOP SLAVE to beginning of dump */ if (opt_slave_apply && add_stop_slave()) goto err;
if (opt_master_data && do_show_master_status(mysql, consistent_binlog_pos,
have_mariadb_gtid,
opt_use_gtid,
master_set_gtid_pos, sizeof(master_set_gtid_pos))) goto err; if (opt_slave_data && do_show_slave_status(mysql,
have_mariadb_gtid,
opt_use_gtid,
slave_set_gtid_pos, sizeof(slave_set_gtid_pos))) goto err; if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */ goto err;
if (opt_alltspcs)
dump_all_tablespaces();
if (extended_insert)
init_dynamic_string_checked(&extended_row, "", 1024, 1024);
if (opt_alldbs)
{ if (!opt_alltspcs && !opt_notspcs)
dump_all_tablespaces();
dump_all_databases();
} else
{ // Check all arguments meet length condition. Currently database and table // names are limited to NAME_LEN bytes and stack-based buffers assumes // that escaped name will be not longer than NAME_LEN*2 + 2 bytes long. int argument; for (argument= 0; argument < argc; argument++)
{
size_t argument_length= strlen(argv[argument]); if (argument_length > NAME_LEN)
{
die(EX_CONSCHECK, "[ERROR] Argument '%s' is too long, it cannot be " "name for any table or database.\n", argv[argument]);
}
}
if (opt_wildcards &&(opt_databases || argc > 1))
{ if (argc > 1 && !opt_databases) /* One database, tables matching the wildcard. */
dump_tables_for_database_wild(argv[0], argc-1, argv+1); elseif (argc > 0) /* Databases matching the wildcards. */
dump_databases_wild(argc, argv); else
die(EX_CONSCHECK, "Incorrect usage of patterns \n");
} else
{ if (argc > 1 && !opt_databases)
{ /* Only one database and selected table(s) */ if (!opt_alltspcs && !opt_notspcs)
dump_tablespaces_for_tables(*argv, (argv + 1), (argc - 1));
dump_selected_tables(*argv, (argv + 1), (argc - 1));
} elseif (argc > 0)
{ /* One or more databases, all tables */ if (!opt_alltspcs && !opt_notspcs)
dump_tablespaces_for_databases(argv);
dump_databases(argv);
}
}
}
if ((opt_system & OPT_SYSTEM_PLUGINS) && dump_all_plugins() && !first_error)
first_error= EX_MYSQLERR;
if ((opt_system & OPT_SYSTEM_USERS) &&
dump_all_users_roles_and_grants() && !first_error)
first_error= EX_MYSQLERR;
if ((opt_system & OPT_SYSTEM_UDFS) && dump_all_udfs() && !first_error)
first_error= EX_MYSQLERR;
if ((opt_system & OPT_SYSTEM_SERVERS) && dump_all_servers() && !first_error)
first_error= EX_MYSQLERR;
/* These must be last as they explicitly change the current database to mysql */ if ((opt_system & OPT_SYSTEM_STATS) && dump_all_stats() && !first_error)
first_error= EX_MYSQLERR;
if ((opt_system & OPT_SYSTEM_TIMEZONES) && dump_all_timezones() && !first_error)
first_error= EX_MYSQLERR;
if (opt_master_data && master_set_gtid_pos[0])
do_print_set_gtid_slave_pos(master_set_gtid_pos, TRUE); if (opt_slave_data && slave_set_gtid_pos[0])
do_print_set_gtid_slave_pos(slave_set_gtid_pos, FALSE);
if (opt_galera_info && dump_galera_info(mysql)) goto err;
/* add 'START SLAVE' to end of dump */ if (opt_slave_apply && add_slave_statements()) goto err;
/* ensure dumped data flushed */ if (md_result_file && fflush(md_result_file))
{ if (!first_error)
first_error= EX_MYSQLERR; goto err;
} /* everything successful, purge the old logs files */ if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name)) goto err;
/* wait for outstanding asynchronous queries */
connection_pool.wait_all();
/* NoreasontoexplicitlyCOMMITthetransaction,neithertoexplicitly UNLOCKTABLES:thesewillbeautomaticallybedonebytheserverwhenwe disconnectnow.Savessomecodehere,somenetworktrips,addsnothingto server.
*/
err: /* if --dump-slave , start the slave sql thread */ if (opt_slave_data)
do_start_slave_sql(mysql);
dbDisconnect(current_host); if (!multi_file_output)
write_footer(md_result_file);
free_resources();
// Galera information exists only if this node is part of cluster if (mysql_query_with_error_report(mysql_con, &wsrep_on_res, "SHOW VARIABLES LIKE 'wsrep_on'")) return1;
if (wsrep_checkpoint_val)
{
fprintf(md_result_file, "SET GLOBAL wsrep_start_position = '%s';\n",
wsrep_checkpoint_val);
}
mysql_free_result(wsrep_checkpoint_res);
}
return0;
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.401Bemerkung:
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.