Skip to content

Commit eedbb90

Browse files
oceanli-hubLinuxJedi
authored andcommitted
[MDEV-14978] Client programs to use $MARIADB_HOST consistently
Only `mysql` client program was using $MYSQL_HOST as the default host. Add the same feature in most other client programs but using $MARIADB_HOST instead. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
1 parent 383d1f9 commit eedbb90

File tree

11 files changed

+152
-17
lines changed

11 files changed

+152
-17
lines changed

client/mysql.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,8 +1738,9 @@ static struct my_option my_long_options[] =
17381738
{"force", 'f',
17391739
"Continue even if we get an SQL error. Sets abort-source-on-error to 0",
17401740
&ignore_errors, &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1741-
{"host", 'h', "Connect to host.", &current_host,
1742-
&current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1741+
{"host", 'h', "Connect to host. Defaults in the following order: "
1742+
"$MARIADB_HOST, $MYSQL_HOST, and then localhost",
1743+
&current_host, &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
17431744
{"html", 'H', "Produce HTML output.", &opt_html, &opt_html,
17441745
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
17451746
{"ignore-spaces", 'i', "Ignore space after function names.",
@@ -2127,7 +2128,10 @@ static int get_options(int argc, char **argv)
21272128
int ho_error;
21282129
MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
21292130

2130-
tmp= (char *) getenv("MYSQL_HOST");
2131+
//MARIADB_HOST will be preferred over MYSQL_HOST.
2132+
tmp= getenv("MARIADB_HOST");
2133+
if (tmp == NULL)
2134+
tmp= getenv("MYSQL_HOST");
21312135
if (tmp)
21322136
current_host= my_strdup(PSI_NOT_INSTRUMENTED, tmp, MYF(MY_WME));
21332137

client/mysqladmin.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ static struct my_option my_long_options[] =
146146
&default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
147147
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG,
148148
NO_ARG, 0, 0, 0, 0, 0, 0},
149-
{"host", 'h', "Connect to host.", &host, &host, 0, GET_STR,
150-
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
149+
{"host", 'h', "Connect to host. Defaults in the following order: "
150+
"$MARIADB_HOST, and then localhost",
151+
&host, &host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
151152
{"local", 'l', "Local command, don't write to binlog.",
152153
&opt_local, &opt_local, 0, GET_BOOL, NO_ARG, 0, 0, 0,
153154
0, 0, 0},
@@ -329,6 +330,9 @@ int main(int argc,char *argv[])
329330
MYSQL mysql;
330331
char **commands, **save_argv, **temp_argv;
331332

333+
if (host == NULL)
334+
host= getenv("MARIADB_HOST");
335+
332336
MY_INIT(argv[0]);
333337
sf_leaking_memory=1; /* don't report memory leaks on early exits */
334338

client/mysqlbinlog.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,9 @@ static struct my_option my_options[] =
14851485
{"hexdump", 'H', "Augment output with hexadecimal and ASCII event dump.",
14861486
&opt_hexdump, &opt_hexdump, 0, GET_BOOL, NO_ARG,
14871487
0, 0, 0, 0, 0, 0},
1488-
{"host", 'h', "Get the binlog from server.", &host, &host,
1489-
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1488+
{"host", 'h', "Get the binlog from server. Defaults in the following order: "
1489+
"$MARIADB_HOST, and then localhost",
1490+
&host, &host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
14901491
{"local-load", 'l', "Prepare local temporary files for LOAD DATA INFILE in the specified directory.",
14911492
&dirname_for_local_load, &dirname_for_local_load, 0,
14921493
GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -2265,6 +2266,11 @@ get_one_option(const struct my_option *opt, const char *argument,
22652266
static int parse_args(int *argc, char*** argv)
22662267
{
22672268
int ho_error;
2269+
char *tmp;
2270+
2271+
tmp= getenv("MARIADB_HOST");
2272+
if (tmp && host == NULL)
2273+
host= my_strdup(PSI_NOT_INSTRUMENTED, tmp, MYF(MY_WME));
22682274

22692275
if ((ho_error=handle_options(argc, argv, my_options, get_one_option)))
22702276
{

client/mysqlcheck.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ static struct my_option my_long_options[] =
145145
0, 0 },
146146
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
147147
NO_ARG, 0, 0, 0, 0, 0, 0},
148-
{"host",'h', "Connect to host.", &current_host,
149-
&current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
148+
{"host",'h', "Connect to host. Defaults in the following order: "
149+
"$MARIADB_HOST, and then localhost",
150+
&current_host, &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
150151
{"medium-check", 'm',
151152
"Faster than extended-check, but only finds 99.99 percent of all errors. Should be good enough for most cases.",
152153
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -413,6 +414,9 @@ static int get_options(int *argc, char ***argv)
413414
int ho_error;
414415
DBUG_ENTER("get_options");
415416

417+
if (current_host == NULL)
418+
current_host= getenv("MARIADB_HOST");
419+
416420
if (*argc == 1)
417421
{
418422
usage();

client/mysqldump.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,9 @@ static struct my_option my_long_options[] =
437437
{"hex-blob", 0, "Dump binary strings (BINARY, "
438438
"VARBINARY, BLOB) in hexadecimal format.",
439439
&opt_hex_blob, &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
440-
{"host", 'h', "Connect to host.", &current_host,
441-
&current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
440+
{"host", 'h', "Connect to host. Defaults in the following order: "
441+
"$MARIADB_HOST, and then localhost",
442+
&current_host, &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
442443
{"ignore-database", OPT_IGNORE_DATABASE,
443444
"Do not dump the specified database. To specify more than one database to ignore, "
444445
"use the directive multiple times, once for each database. Only takes effect "
@@ -1107,9 +1108,14 @@ get_one_option(const struct my_option *opt,
11071108

11081109
static int get_options(int *argc, char ***argv)
11091110
{
1111+
char *tmp;
11101112
int ho_error;
11111113
MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
11121114

1115+
tmp= getenv("MARIADB_HOST");
1116+
if (tmp && current_host == NULL)
1117+
current_host= my_strdup(PSI_NOT_INSTRUMENTED, tmp, MYF(MY_WME));
1118+
11131119
opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
11141120
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
11151121

client/mysqlimport.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ static struct my_option my_long_options[] =
149149
0, 0, 0, 0},
150150
{"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG, NO_ARG,
151151
0, 0, 0, 0, 0, 0},
152-
{"host", 'h', "Connect to host.", &current_host,
153-
&current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
152+
{"host", 'h', "Connect to host. Defaults in the following order: "
153+
"$MARIADB_HOST, and then localhost",
154+
&current_host, &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
154155
{"ignore", 'i', "If duplicate unique key was found, keep old row.",
155156
&ignore, &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
156157
{"ignore-foreign-keys", 'k',
@@ -367,6 +368,9 @@ static int get_options(int *argc, char ***argv)
367368
{
368369
int ho_error;
369370

371+
if (current_host == NULL)
372+
current_host= getenv("MARIADB_HOST");
373+
370374
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
371375
exit(ho_error);
372376
if (debug_info_flag)

client/mysqlshow.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ static struct my_option my_long_options[] =
204204
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
205205
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
206206
0, 0, 0, 0, 0, 0},
207-
{"host", 'h', "Connect to host.", &host, &host, 0, GET_STR,
208-
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
207+
{"host", 'h', "Connect to host. Defaults in the following order: "
208+
"$MARIADB_HOST, and then localhost",
209+
&host, &host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
209210
{"status", 'i', "Shows a lot of extra information about each table.",
210211
&opt_status, &opt_status, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
211212
0, 0},
@@ -363,6 +364,9 @@ get_options(int *argc,char ***argv)
363364
{
364365
int ho_error;
365366

367+
if (host == NULL)
368+
host= getenv("MARIADB_HOST");
369+
366370
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
367371
exit(ho_error);
368372

client/mysqlslap.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,9 @@ static struct my_option my_long_options[] =
611611
"engine after a `:', like memory:max_row=2300",
612612
&default_engine, &default_engine, 0,
613613
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
614-
{"host", 'h', "Connect to host.", &host, &host, 0, GET_STR,
615-
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
614+
{"host", 'h', "Connect to host. Defaults in the following order: "
615+
"$MARIADB_HOST, and then localhost",
616+
&host, &host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
616617
{"init-command", 0,
617618
"SQL Command to execute when connecting to MariaDB server. Will "
618619
"automatically be re-executed when reconnecting.",
@@ -1186,6 +1187,9 @@ get_options(int *argc,char ***argv)
11861187
if (debug_check_flag)
11871188
my_end_arg= MY_CHECK_ERROR;
11881189

1190+
if (host == NULL)
1191+
host= getenv("MARIADB_HOST");
1192+
11891193
/*
11901194
If something is created and --no-drop is not specified, we drop the
11911195
schema.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
!include include/default_my.cnf
2+
3+
[ENV]
4+
MARIADB_HOST=localhost
5+
MYSQL_HOST=some_server
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
USE test;
2+
CREATE TABLE pet (name VARCHAR(20));
3+
localhost
4+
****************
5+
nonexistent-server
6+
Done
7+
DROP TABLE pet;

0 commit comments

Comments
 (0)