From f88fcf2514c64df8408e9df41dc129ab6f655c18 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Mon, 30 Oct 2017 07:37:25 +0400 Subject: [PATCH] MDEV-12542 Add bind_address system variable. bind_address variable added. --- .../sys_vars/r/bind_address_basic.result | 57 +++++++++++ .../r/sysvars_server_notembedded.result | 14 +++ .../suite/sys_vars/t/bind_address_basic.test | 95 +++++++++++++++++++ sql/mysqld.cc | 3 - sql/mysqld.h | 1 + sql/sys_vars.cc | 7 ++ 6 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/sys_vars/r/bind_address_basic.result create mode 100644 mysql-test/suite/sys_vars/t/bind_address_basic.test diff --git a/mysql-test/suite/sys_vars/r/bind_address_basic.result b/mysql-test/suite/sys_vars/r/bind_address_basic.result new file mode 100644 index 00000000000..f360433a90c --- /dev/null +++ b/mysql-test/suite/sys_vars/r/bind_address_basic.result @@ -0,0 +1,57 @@ +'#---------------------BS_STVARS_001_01----------------------#' +SELECT COUNT(@@GLOBAL.bind_address); +COUNT(@@GLOBAL.bind_address) +1 +1 Expected +'#---------------------BS_STVARS_001_02----------------------#' +SET @@GLOBAL.bind_address=1; +ERROR HY000: Variable 'bind_address' is a read only variable +Expected error 'Read only variable' +SELECT COUNT(@@GLOBAL.bind_address); +COUNT(@@GLOBAL.bind_address) +1 +1 Expected +'#---------------------BS_STVARS_001_03----------------------#' +SELECT VARIABLE_VALUE = '' +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='bind_address'; +VARIABLE_VALUE = '' +0 +0 Expected +SELECT COUNT(@@GLOBAL.bind_address); +COUNT(@@GLOBAL.bind_address) +1 +1 Expected +SELECT COUNT(VARIABLE_VALUE) +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='bind_address'; +COUNT(VARIABLE_VALUE) +1 +1 Expected +'#---------------------BS_STVARS_001_04----------------------#' +SELECT @@bind_address is NULL AND @@GLOBAL.bind_address is NULL; +@@bind_address is NULL AND @@GLOBAL.bind_address is NULL +0 +0 Expected +SELECT @@bind_address is NOT NULL AND @@GLOBAL.bind_address is NOT NULL; +@@bind_address is NOT NULL AND @@GLOBAL.bind_address is NOT NULL +1 +1 Expected +'#---------------------BS_STVARS_001_05----------------------#' +SELECT COUNT(@@bind_address); +COUNT(@@bind_address) +1 +1 Expected +SELECT COUNT(@@local.bind_address); +ERROR HY000: Variable 'bind_address' is a GLOBAL variable +Expected error 'Variable is a GLOBAL variable' +SELECT COUNT(@@SESSION.bind_address); +ERROR HY000: Variable 'bind_address' is a GLOBAL variable +Expected error 'Variable is a GLOBAL variable' +SELECT COUNT(@@GLOBAL.bind_address); +COUNT(@@GLOBAL.bind_address) +1 +1 Expected +SELECT bind_address = @@SESSION.bind_address; +ERROR 42S22: Unknown column 'bind_address' in 'field list' +Expected error 'Readonly variable' diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 5dcefb3ffe2..6124cf4a908 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -122,6 +122,20 @@ NUMERIC_BLOCK_SIZE NULL ENUM_VALUE_LIST OFF,ON READ_ONLY NO COMMAND_LINE_ARGUMENT OPTIONAL +VARIABLE_NAME BIND_ADDRESS +SESSION_VALUE NULL +GLOBAL_VALUE 127.0.0.1 +GLOBAL_VALUE_ORIGIN CONFIG +DEFAULT_VALUE +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE VARCHAR +VARIABLE_COMMENT IP address to bind to. +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME BINLOG_ANNOTATE_ROW_EVENTS SESSION_VALUE ON GLOBAL_VALUE ON diff --git a/mysql-test/suite/sys_vars/t/bind_address_basic.test b/mysql-test/suite/sys_vars/t/bind_address_basic.test new file mode 100644 index 00000000000..f7c567b36b8 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/bind_address_basic.test @@ -0,0 +1,95 @@ + + +################## mysql-test\t\bind_address_basic.test ############################ +# # +# Variable Name: bind_address # +# Scope: Global # +# Access Type: Static # +# Data Type: filename # +############################################################################### + +--source include/not_embedded.inc + +--echo '#---------------------BS_STVARS_001_01----------------------#' +#################################################################### +# Displaying default value # +#################################################################### +SELECT COUNT(@@GLOBAL.bind_address); +--echo 1 Expected + + +--echo '#---------------------BS_STVARS_001_02----------------------#' +#################################################################### +# Check if Value can set # +#################################################################### + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +SET @@GLOBAL.bind_address=1; +--echo Expected error 'Read only variable' + +SELECT COUNT(@@GLOBAL.bind_address); +--echo 1 Expected + + + + +--echo '#---------------------BS_STVARS_001_03----------------------#' +################################################################# +# Check if the value in GLOBAL Table matches value in variable # +################################################################# + +--disable_warnings +SELECT VARIABLE_VALUE = '' +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='bind_address'; +--enable_warnings +--echo 0 Expected + +SELECT COUNT(@@GLOBAL.bind_address); +--echo 1 Expected + +--disable_warnings +SELECT COUNT(VARIABLE_VALUE) +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='bind_address'; +--enable_warnings +--echo 1 Expected + + + +--echo '#---------------------BS_STVARS_001_04----------------------#' +################################################################################ +# Check if accessing variable with and without GLOBAL point to same variable # +################################################################################ +SELECT @@bind_address is NULL AND @@GLOBAL.bind_address is NULL; +--echo 0 Expected + +SELECT @@bind_address is NOT NULL AND @@GLOBAL.bind_address is NOT NULL; +--echo 1 Expected + + + +--echo '#---------------------BS_STVARS_001_05----------------------#' +################################################################################ +# Check if bind_address can be accessed with and without @@ sign # +################################################################################ + +SELECT COUNT(@@bind_address); +--echo 1 Expected + +--Error ER_INCORRECT_GLOBAL_LOCAL_VAR +SELECT COUNT(@@local.bind_address); +--echo Expected error 'Variable is a GLOBAL variable' + +--Error ER_INCORRECT_GLOBAL_LOCAL_VAR +SELECT COUNT(@@SESSION.bind_address); +--echo Expected error 'Variable is a GLOBAL variable' + +SELECT COUNT(@@GLOBAL.bind_address); +--echo 1 Expected + +--Error ER_BAD_FIELD_ERROR +SELECT bind_address = @@SESSION.bind_address; +--echo Expected error 'Readonly variable' + + diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 8f9a62de4c6..4fcdc37c912 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7297,9 +7297,6 @@ struct my_option my_long_options[]= {"autocommit", 0, "Set default value for autocommit (0 or 1)", &opt_autocommit, &opt_autocommit, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, NULL}, - {"bind-address", 0, "IP address to bind to.", - &my_bind_addr_str, &my_bind_addr_str, 0, GET_STR, - REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"binlog-do-db", OPT_BINLOG_DO_DB, "Tells the master it should log updates for the specified database, " "and exclude all others not explicitly mentioned.", diff --git a/sql/mysqld.h b/sql/mysqld.h index 15208d4e2f5..8364eecdb7c 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -152,6 +152,7 @@ extern my_bool opt_enable_shared_memory; extern ulong opt_replicate_events_marked_for_skip; extern char *default_tz_name; extern Time_zone *default_tz; +extern char *my_bind_addr_str; extern char *default_storage_engine, *default_tmp_storage_engine; extern char *enforced_storage_engine; extern char *gtid_pos_auto_engines; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index daf13ee56f9..87318694bab 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -382,6 +382,13 @@ static Sys_var_charptr Sys_basedir( READ_ONLY GLOBAL_VAR(mysql_home_ptr), CMD_LINE(REQUIRED_ARG, 'b'), IN_FS_CHARSET, DEFAULT(0)); +#ifndef EMBEDDED_LIBRARY +static Sys_var_charptr Sys_my_bind_addr( + "bind_address", "IP address to bind to.", + READ_ONLY GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG), + IN_FS_CHARSET, DEFAULT(0)); +#endif + static Sys_var_ulonglong Sys_binlog_cache_size( "binlog_cache_size", "The size of the transactional cache for " "updates to transactional engines for the binary log. "