Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ static int sigint_received= 0;
#endif
static char *current_host,*current_db,*current_user=0,*opt_password=0,
*current_prompt=0, *delimiter_str= 0,
*default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME,
*opt_init_command= 0;
*default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
static char *histfile;
static char *histfile_tmp;
static String glob_buffer,old_buffer;
Expand Down Expand Up @@ -308,6 +307,7 @@ static uint opt_protocol=0;
static const char *opt_protocol_type= "";

#include "sslopt-vars.h"
#include "common-cli-vars.h"

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

Expand Down Expand Up @@ -1833,10 +1833,6 @@ static struct my_option my_long_options[] =
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"ignore-spaces", 'i', "Ignore space after function names.",
&ignore_spaces, &ignore_spaces, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"init-command", 0,
"SQL Command to execute when connecting to MariaDB server. Will "
"automatically be re-executed when reconnecting.", &opt_init_command,
&opt_init_command, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"line-numbers", 0, "Write line numbers for errors.",
&line_numbers, &line_numbers, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"skip-line-numbers", 'L', "Don't write line number for errors.", 0, 0, 0,
Expand Down Expand Up @@ -1948,6 +1944,7 @@ static struct my_option my_long_options[] =
&opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR_ALLOC,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include "sslopt-longopts.h"
#include "common-cli-longopts.h"
{"table", 't', "Output in table format.", &output_tables,
&output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"tee", OPT_TEE,
Expand Down
5 changes: 5 additions & 0 deletions client/mysqldump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ static MYSQL_RES *routine_res, *routine_list_res, *slave_status_res= NULL;


#include <sslopt-vars.h>
#include <common-cli-vars.h>
FILE *md_result_file= 0;
FILE *stderror_file=0;

Expand Down Expand Up @@ -592,6 +593,7 @@ static struct my_option my_long_options[] =
&opt_mysql_unix_port, &opt_mysql_unix_port, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include <sslopt-longopts.h>
#include <common-cli-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',
Expand Down Expand Up @@ -2106,6 +2108,9 @@ static MYSQL* connect_to_db(char *host, char *user,char *passwd)
if (opt_default_auth && *opt_default_auth)
mysql_options(con, MYSQL_DEFAULT_AUTH, opt_default_auth);

if (opt_init_command && *opt_init_command)
mysql_options(con, MYSQL_INIT_COMMAND, opt_init_command);

mysql_options(con, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
mysql_options4(con, MYSQL_OPT_CONNECT_ATTR_ADD,
"program_name", "mysqldump");
Expand Down
10 changes: 3 additions & 7 deletions client/mysqlslap.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <my_dir.h>
#include <signal.h>
#include <sslopt-vars.h>
#include <common-cli-vars.h>
#ifndef _WIN32
#include <sys/wait.h>
#endif
Expand Down Expand Up @@ -118,8 +119,7 @@ static char *host= NULL, *opt_password= NULL, *user= NULL,
*default_engine= NULL,
*pre_system= NULL,
*post_system= NULL,
*opt_mysql_unix_port= NULL,
*opt_init_command= NULL;
*opt_mysql_unix_port= NULL;
static char *opt_plugin_dir= 0, *opt_default_auth= 0;

const char *delimiter= "\n";
Expand Down Expand Up @@ -617,11 +617,6 @@ static struct my_option my_long_options[] =
{"host", 'h', "Connect to host. Defaults in the following order: "
"$MARIADB_HOST, and then localhost",
&host, &host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"init-command", 0,
"SQL Command to execute when connecting to MariaDB server. Will "
"automatically be re-executed when reconnecting.",
&opt_init_command, &opt_init_command, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"iterations", 'i', "Number of times to run the tests.", &iterations,
&iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
{"no-drop", 0, "Do not drop the schema after the test.",
Expand Down Expand Up @@ -685,6 +680,7 @@ static struct my_option my_long_options[] =
&opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include <sslopt-longopts.h>
#include <common-cli-longopts.h>
#ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", &user,
&user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
Expand Down
10 changes: 10 additions & 0 deletions include/common-cli-longopts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef COMMON_CLI_LONGOPTS_INCLUDED
#define COMMON_CLI_LONGOPTS_INCLUDED

{"init-command", 0,
"SQL Command to execute when connecting to MariaDB server. Will "
"automatically be re-executed when reconnecting.",
&opt_init_command, &opt_init_command, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},

#endif /* COMMON_CLI_LONGOPTS_INCLUDED */
6 changes: 6 additions & 0 deletions include/common-cli-vars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef COMMON_CLI_VARS_INCLUDED
#define COMMON_CLI_VARS_INCLUDED

static char *opt_init_command= 0;

#endif /* COMMON_CLI_VARS_INCLUDED */
23 changes: 23 additions & 0 deletions mysql-test/main/mysqldump-init-command.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE DATABASE 28911_mysqldump;
USE 28911_mysqldump;
CREATE TABLE t1(id INT, ts TIMESTAMP);
SET time_zone='+00:00';
INSERT INTO t1 VALUES (1, '2026-01-01 12:00:00');

# dump with --init-command="SET SESSION time_zone='+05:00'" (INSERT shows 17:00:00)
/*M!999999\- enable the sandbox mode */
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL,
`ts` timestamp NULL DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
INSERT INTO `t1` VALUES
(1,'2026-01-01 17:00:00');
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
DROP TABLE t1;
DROP DATABASE 28911_mysqldump;
# End of MDEV-28911
18 changes: 18 additions & 0 deletions mysql-test/main/mysqldump-init-command.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--source include/not_embedded.inc

# MDEV-28911: Add --init-command option to mariadb-dump / mysqldump

CREATE DATABASE 28911_mysqldump;
USE 28911_mysqldump;
CREATE TABLE t1(id INT, ts TIMESTAMP);
SET time_zone='+00:00';
INSERT INTO t1 VALUES (1, '2026-01-01 12:00:00');

--echo
--echo # dump with --init-command="SET SESSION time_zone='+05:00'" (INSERT shows 17:00:00)
--exec $MYSQL_DUMP --compact --skip-comments --skip-tz-utc --init-command="SET SESSION time_zone='+05:00'" 28911_mysqldump

DROP TABLE t1;
DROP DATABASE 28911_mysqldump;

--echo # End of MDEV-28911