Skip to content

Commit 38a8522

Browse files
author
Alexander Nozdrin
committed
Auto-merge from mysql-next-mr-stage.
2 parents 617e0e9 + 7123f35 commit 38a8522

20 files changed

+206
-9
lines changed

client/mysql.cc

+6
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static ulong opt_max_allowed_packet, opt_net_buffer_length;
152152
static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
153153
static uint my_end_arg;
154154
static char * opt_mysql_unix_port=0;
155+
static char *opt_bind_addr = NULL;
155156
static int connect_flag=CLIENT_INTERACTIVE;
156157
static char *current_host,*current_db,*current_user=0,*opt_password=0,
157158
*current_prompt=0, *delimiter_str= 0,
@@ -1376,6 +1377,9 @@ static struct my_option my_long_options[] =
13761377
{"batch", 'B',
13771378
"Don't use history file. Disable interactive behavior. (Enables --silent.)",
13781379
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1380+
{"bind-address", 0, "IP address to bind to.",
1381+
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
1382+
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
13791383
{"character-sets-dir", OPT_CHARSETS_DIR,
13801384
"Directory for character set files.", &charsets_dir,
13811385
&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -4265,6 +4269,8 @@ sql_real_connect(char *host,char *database,char *user,char *password,
42654269
mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT,
42664270
(char*) &timeout);
42674271
}
4272+
if (opt_bind_addr)
4273+
mysql_options(&mysql, MYSQL_OPT_BIND, opt_bind_addr);
42684274
if (opt_compress)
42694275
mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
42704276
if (opt_secure_auth)

client/mysqladmin.cc

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static my_bool option_force=0,interrupted=0,new_line=0,
4141
static my_bool debug_info_flag= 0, debug_check_flag= 0;
4242
static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations;
4343
static uint opt_count_iterations= 0, my_end_arg;
44+
static char *opt_bind_addr = NULL;
4445
static ulong opt_connect_timeout, opt_shutdown_timeout;
4546
static char * unix_port=0;
4647

@@ -116,6 +117,9 @@ static TYPELIB command_typelib=
116117

117118
static struct my_option my_long_options[] =
118119
{
120+
{"bind-address", 0, "IP address to bind to.",
121+
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
122+
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
119123
{"count", 'c',
120124
"Number of iterations to make. This works with -i (--sleep) only.",
121125
&nr_iterations, &nr_iterations, 0, GET_UINT,
@@ -318,6 +322,8 @@ int main(int argc,char *argv[])
318322
(void) signal(SIGINT,endprog); /* Here if abort */
319323
(void) signal(SIGTERM,endprog); /* Here if abort */
320324

325+
if (opt_bind_addr)
326+
mysql_options(&mysql,MYSQL_OPT_BIND,opt_bind_addr);
321327
if (opt_compress)
322328
mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
323329
if (opt_connect_timeout)

client/mysqlbinlog.cc

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static char *shared_memory_base_name= 0;
8989
#endif
9090
static char* user = 0;
9191
static char* pass = 0;
92+
static char *opt_bind_addr = NULL;
9293
static char *charset= 0;
9394

9495
static uint verbose= 0;
@@ -1024,6 +1025,9 @@ static struct my_option my_long_options[] =
10241025
"argument, 'always' is used.",
10251026
&opt_base64_output_mode_str, &opt_base64_output_mode_str,
10261027
0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1028+
{"bind-address", 0, "IP address to bind to.",
1029+
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
1030+
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
10271031
/*
10281032
mysqlbinlog needs charsets knowledge, to be able to convert a charset
10291033
number found in binlog to a charset name (to be able to print things
@@ -1419,6 +1423,8 @@ static Exit_status safe_connect()
14191423

14201424
if (opt_protocol)
14211425
mysql_options(mysql, MYSQL_OPT_PROTOCOL, (char*) &opt_protocol);
1426+
if (opt_bind_addr)
1427+
mysql_options(mysql, MYSQL_OPT_BIND, opt_bind_addr);
14221428
#ifdef HAVE_SMEM
14231429
if (shared_memory_base_name)
14241430
mysql_options(mysql, MYSQL_SHARED_MEMORY_BASE_NAME,

client/mysqlcheck.c

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ DYNAMIC_ARRAY tables4repair;
4747
static char *shared_memory_base_name=0;
4848
#endif
4949
static uint opt_protocol=0;
50+
static char *opt_bind_addr = NULL;
5051

5152
enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
5253

@@ -66,6 +67,9 @@ static struct my_option my_long_options[] =
6667
"If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
6768
&opt_auto_repair, &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
6869
0, 0, 0, 0, 0},
70+
{"bind-address", 0, "IP address to bind to.",
71+
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
72+
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
6973
{"character-sets-dir", OPT_CHARSETS_DIR,
7074
"Directory for character set files.", &charsets_dir,
7175
&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -786,6 +790,8 @@ static int dbConnect(char *host, char *user, char *passwd)
786790
#endif
787791
if (opt_protocol)
788792
mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
793+
if (opt_bind_addr)
794+
mysql_options(&mysql_connection, MYSQL_OPT_BIND, opt_bind_addr);
789795
#ifdef HAVE_SMEM
790796
if (shared_memory_base_name)
791797
mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);

client/mysqldump.c

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static uint opt_mysql_port= 0, opt_master_data;
125125
static uint opt_slave_data;
126126
static uint my_end_arg;
127127
static char * opt_mysql_unix_port=0;
128+
static char *opt_bind_addr = NULL;
128129
static int first_error=0;
129130
static DYNAMIC_STRING extended_row;
130131
#include <sslopt-vars.h>
@@ -214,6 +215,9 @@ static struct my_option my_long_options[] =
214215
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
215216
&opt_slave_apply, &opt_slave_apply, 0, GET_BOOL, NO_ARG,
216217
0, 0, 0, 0, 0, 0},
218+
{"bind-address", 0, "IP address to bind to.",
219+
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
220+
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
217221
{"character-sets-dir", OPT_CHARSETS_DIR,
218222
"Directory for character set files.", &charsets_dir,
219223
&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -1449,6 +1453,8 @@ static int connect_to_db(char *host, char *user,char *passwd)
14491453
#endif
14501454
if (opt_protocol)
14511455
mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
1456+
if (opt_bind_addr)
1457+
mysql_options(&mysql_connection,MYSQL_OPT_BIND,opt_bind_addr);
14521458
#ifdef HAVE_SMEM
14531459
if (shared_memory_base_name)
14541460
mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);

client/mysqlimport.c

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static char *opt_password=0, *current_user=0,
5757
*escaped=0, *opt_columns=0,
5858
*default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
5959
static uint opt_mysql_port= 0, opt_protocol= 0;
60+
static char *opt_bind_addr = NULL;
6061
static char * opt_mysql_unix_port=0;
6162
static longlong opt_ignore_lines= -1;
6263
#include <sslopt-vars.h>
@@ -67,6 +68,9 @@ static char *shared_memory_base_name=0;
6768

6869
static struct my_option my_long_options[] =
6970
{
71+
{"bind-address", 0, "IP address to bind to.",
72+
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
73+
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
7074
{"character-sets-dir", OPT_CHARSETS_DIR,
7175
"Directory for character set files.", &charsets_dir,
7276
&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -424,6 +428,8 @@ static MYSQL *db_connect(char *host, char *database,
424428
#endif
425429
if (opt_protocol)
426430
mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
431+
if (opt_bind_addr)
432+
mysql_options(mysql,MYSQL_OPT_BIND,opt_bind_addr);
427433
#ifdef HAVE_SMEM
428434
if (shared_memory_base_name)
429435
mysql_options(mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);

client/mysqlshow.c

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static char *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
3838
static char *shared_memory_base_name=0;
3939
#endif
4040
static uint opt_protocol=0;
41+
static char *opt_bind_addr = NULL;
4142

4243
static void get_options(int *argc,char ***argv);
4344
static uint opt_mysql_port=0;
@@ -117,6 +118,8 @@ int main(int argc, char **argv)
117118
#endif
118119
if (opt_protocol)
119120
mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
121+
if (opt_bind_addr)
122+
mysql_options(&mysql,MYSQL_OPT_BIND,opt_bind_addr);
120123
#ifdef HAVE_SMEM
121124
if (shared_memory_base_name)
122125
mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
@@ -160,6 +163,9 @@ int main(int argc, char **argv)
160163

161164
static struct my_option my_long_options[] =
162165
{
166+
{"bind-address", 0, "IP address to bind to.",
167+
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
168+
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
163169
{"character-sets-dir", 'c', "Directory for character set files.",
164170
&charsets_dir, &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0,
165171
0, 0, 0, 0, 0},

include/mysql.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ enum mysql_option
167167
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
168168
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
169169
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
170-
MYSQL_OPT_SSL_VERIFY_SERVER_CERT
170+
MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_OPT_BIND
171171
};
172172

173173
struct st_mysql_options {
@@ -191,7 +191,20 @@ struct st_mysql_options {
191191
my_bool unused3;
192192
my_bool unused4;
193193
enum mysql_option methods_to_use;
194-
char *client_ip;
194+
union {
195+
/*
196+
The ip/hostname to use when authenticating
197+
client against embedded server built with
198+
grant tables - only used in embedded server
199+
*/
200+
char *client_ip;
201+
202+
/*
203+
The local address to bind when connecting to
204+
remote server - not used in embedded server
205+
*/
206+
char *bind_address;
207+
} ci;
195208
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
196209
my_bool secure_auth;
197210
/* 0 - never report, 1 - always report (default) */

include/mysql.h.pp

+5-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
263263
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
264264
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
265-
MYSQL_OPT_SSL_VERIFY_SERVER_CERT
265+
MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_OPT_BIND
266266
};
267267
struct st_mysql_options {
268268
unsigned int connect_timeout, read_timeout, write_timeout;
@@ -285,7 +285,10 @@
285285
my_bool unused3;
286286
my_bool unused4;
287287
enum mysql_option methods_to_use;
288-
char *client_ip;
288+
union {
289+
char *client_ip;
290+
char *bind_address;
291+
} ci;
289292
my_bool secure_auth;
290293
my_bool report_data_truncation;
291294
int (*local_infile_init)(void **, const char *, void *);

mysql-test/r/mysql.result

+2
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,5 @@ Bug #47147: mysql client option --skip-column-names does not apply to vertical o
434434
1
435435

436436
End of tests
437+
Connected
438+
1

mysql-test/r/mysqladmin.result

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ mysqld is alive
22
mysqladmin: unknown variable 'database=db1'
33
Warning: mysqladmin: unknown variable 'loose-database=db2'
44
mysqld is alive
5+
mysqld is alive

mysql-test/r/mysqldump.result

+5
Original file line numberDiff line numberDiff line change
@@ -4575,6 +4575,11 @@ SELECT LENGTH(a) FROM t2;
45754575
LENGTH(a)
45764576
800
45774577
DROP TABLE t1, t2;
4578+
create table t1 (first char(28) , last varchar(37));
4579+
insert into t1 values ("Magnus", "Blåudd");
4580+
truncate table t1;
4581+
test.t1: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
4582+
drop table t1;
45784583
#
45794584
# End of 5.1 tests
45804585
#

mysql-test/r/mysqlshow.result

+5
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,9 @@ Wildcard: inf_rmation_schema
181181
+--------------------+
182182
| information_schema |
183183
+--------------------+
184+
Database: test
185+
+--------+
186+
| Tables |
187+
+--------+
188+
+--------+
184189
End of 5.0 tests

mysql-test/t/mysql.test

+7
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,10 @@ drop table t1;
427427

428428
--echo
429429
--echo End of tests
430+
431+
432+
#
433+
# WL#3126 TCP address binding for mysql client library;
434+
# - running mysql --protocol=tcp --bind-address=127.0.0.1
435+
#
436+
--exec $MYSQL --protocol=tcp --bind-address=127.0.0.1 -e "select 1 as Connected"

mysql-test/t/mysqladmin.test

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ EOF
3333
--exec $MYSQLADMIN --defaults-file=$MYSQLTEST_VARDIR/tmp/bug10608.cnf --default-character-set=latin1 -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1
3434

3535
remove_file $MYSQLTEST_VARDIR/tmp/bug10608.cnf;
36+
37+
#
38+
# WL#3126 TCP address binding for mysql client library;
39+
# - running mysqladmin --protcol=tcp --bind-address=127.0.0.1
40+
#
41+
--exec $MYSQLADMIN --no-defaults --protocol=tcp --bind-address=127.0.0.1 --host=127.0.0.1 -P $MASTER_MYPORT -u root ping 2>&1

mysql-test/t/mysqlbinlog.test

+7
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,10 @@ diff_files $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn $MYSQLTEST_VARDIR/tmp/mysqlbin
487487
# Cleanup for this part of test
488488
remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
489489
remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn;
490+
491+
#
492+
# WL#3126 TCP address binding for mysql client library;
493+
# - running mysqlbinlog --protocol=tcp --bind-address=127.0.0.1
494+
#
495+
--exec $MYSQL_BINLOG --short-form --read-from-remote-server --protocol=tcp --bind-address=127.0.0.1 master-bin.000001 > /dev/null
496+

mysql-test/t/mysqlcheck.test

+7
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,11 @@ create table `#mysql50#t1-1` (a int);
211211
show tables like 't1-1';
212212
drop table `t1-1`;
213213

214+
#
215+
# WL#3126 TCP address binding for mysql client library;
216+
# - running mysqlcheck --protcol=tcp --bind-address=127.0.0.1
217+
#
218+
--exec $MYSQL_CHECK --protocol=tcp --bind-address=127.0.0.1 --databases test
219+
214220
--echo End of 5.1 tests
221+

mysql-test/t/mysqldump.test

+12
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,18 @@ SELECT LENGTH(a) FROM t2;
21682168

21692169
DROP TABLE t1, t2;
21702170

2171+
#
2172+
# WL#3126 TCP address binding for mysql client library;
2173+
# - running mysqldump --protocol=tcp --bind-address=127.0.0.1
2174+
# - running mysqlimport --protocol=tcp --bind-address=127.0.0.1
2175+
#
2176+
create table t1 (first char(28) , last varchar(37));
2177+
insert into t1 values ("Magnus", "Blåudd");
2178+
--exec $MYSQL_DUMP --protocol=tcp --bind-address=127.0.0.1 --tab=$MYSQLTEST_VARDIR/tmp/ test
2179+
truncate table t1;
2180+
--exec $MYSQL_IMPORT --protocol=tcp --bind-address=127.0.0.1 test $MYSQLTEST_VARDIR/tmp/t1.txt
2181+
drop table t1;
2182+
21712183
###########################################################################
21722184
--echo #
21732185
--echo # End of 5.1 tests

mysql-test/t/mysqlshow.test

+6
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ DROP TABLE t1, t2;
3535
--exec $MYSQL_SHOW INFORMATION_SCHEMA
3636
--exec $MYSQL_SHOW inf_rmation_schema
3737

38+
#
39+
# WL#3126 TCP address binding for mysql client library;
40+
# - running mysqlshow --protcol=tcp --bind-address=127.0.0.1
41+
#
42+
--exec $MYSQL_SHOW --protocol=tcp --bind-address=127.0.0.1 test
43+
3844
--echo End of 5.0 tests

0 commit comments

Comments
 (0)