mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Bug #47423 mtr connects to wrong database
The reason for the bug is that mysqtest as well as other client tools running in test suite (mysqlbinlog, mysqldump) will first try to connect whatever database has created shared memory with default base name "MySQL" and use this. (Same effect could be seen on Unix if mtr would not care to calculate "port" and "socket" parameter). The fix ensures that all client tools and running in mtr use unique per-database shared memory base parameters, so there is no possibility to clash with already installed one. We use socket name for shared memory base (it's known to be unique). This shared-memory-base is written to the MTR config file to the [client] and [mysqld] sections. Fix made also made sure all client tools understand and correctly handle --shared-memory-base. Prior to this patch it was not the case for mysqltest, mysqlbinlog and mysql_client_test. All new connections done from mtr scripts via connect() will by default set shared-memory-base. And finally, there is a possibility to force shared memory or pipe connection and overwrite shared memory/pipe base name from within mtr scripts via optional PIPE or SHM modifier. This functionality was manually backported from 6.0 (original patch http://lists.mysql.com/commits/74749)
This commit is contained in:
@@ -81,6 +81,9 @@ enum {
|
||||
static int record= 0, opt_sleep= -1;
|
||||
static char *opt_db= 0, *opt_pass= 0;
|
||||
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
|
||||
#ifdef HAVE_SMEM
|
||||
static char *shared_memory_base_name=0;
|
||||
#endif
|
||||
const char *opt_logdir= "";
|
||||
const char *opt_include= 0, *opt_charsets_dir;
|
||||
static int opt_port= 0;
|
||||
@@ -4896,6 +4899,8 @@ do_handle_error:
|
||||
<opts> - options to use for the connection
|
||||
* SSL - use SSL if available
|
||||
* COMPRESS - use compression if available
|
||||
* SHM - use shared memory if available
|
||||
* PIPE - use named pipe if available
|
||||
|
||||
*/
|
||||
|
||||
@@ -4904,6 +4909,7 @@ void do_connect(struct st_command *command)
|
||||
int con_port= opt_port;
|
||||
char *con_options;
|
||||
my_bool con_ssl= 0, con_compress= 0;
|
||||
my_bool con_pipe= 0, con_shm= 0;
|
||||
struct st_connection* con_slot;
|
||||
|
||||
static DYNAMIC_STRING ds_connection_name;
|
||||
@@ -4914,6 +4920,9 @@ void do_connect(struct st_command *command)
|
||||
static DYNAMIC_STRING ds_port;
|
||||
static DYNAMIC_STRING ds_sock;
|
||||
static DYNAMIC_STRING ds_options;
|
||||
#ifdef HAVE_SMEM
|
||||
static DYNAMIC_STRING ds_shm;
|
||||
#endif
|
||||
const struct command_arg connect_args[] = {
|
||||
{ "connection name", ARG_STRING, TRUE, &ds_connection_name, "Name of the connection" },
|
||||
{ "host", ARG_STRING, TRUE, &ds_host, "Host to connect to" },
|
||||
@@ -4941,6 +4950,11 @@ void do_connect(struct st_command *command)
|
||||
die("Illegal argument for port: '%s'", ds_port.str);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SMEM
|
||||
/* Shared memory */
|
||||
init_dynamic_string(&ds_shm, ds_sock.str, 0, 0);
|
||||
#endif
|
||||
|
||||
/* Sock */
|
||||
if (ds_sock.length)
|
||||
{
|
||||
@@ -4979,6 +4993,10 @@ void do_connect(struct st_command *command)
|
||||
con_ssl= 1;
|
||||
else if (!strncmp(con_options, "COMPRESS", 8))
|
||||
con_compress= 1;
|
||||
else if (!strncmp(con_options, "PIPE", 4))
|
||||
con_pipe= 1;
|
||||
else if (!strncmp(con_options, "SHM", 3))
|
||||
con_shm= 1;
|
||||
else
|
||||
die("Illegal option to connect: %.*s",
|
||||
(int) (end - con_options), con_options);
|
||||
@@ -5026,6 +5044,31 @@ void do_connect(struct st_command *command)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __WIN__
|
||||
if (con_pipe)
|
||||
{
|
||||
uint protocol= MYSQL_PROTOCOL_PIPE;
|
||||
mysql_options(&con_slot->mysql, MYSQL_OPT_PROTOCOL, &protocol);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SMEM
|
||||
if (con_shm)
|
||||
{
|
||||
uint protocol= MYSQL_PROTOCOL_MEMORY;
|
||||
if (!ds_shm.length)
|
||||
die("Missing shared memory base name");
|
||||
mysql_options(&con_slot->mysql, MYSQL_SHARED_MEMORY_BASE_NAME, ds_shm.str);
|
||||
mysql_options(&con_slot->mysql, MYSQL_OPT_PROTOCOL, &protocol);
|
||||
}
|
||||
else if(shared_memory_base_name)
|
||||
{
|
||||
mysql_options(&con_slot->mysql, MYSQL_SHARED_MEMORY_BASE_NAME,
|
||||
shared_memory_base_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Use default db name */
|
||||
if (ds_database.length == 0)
|
||||
dynstr_set(&ds_database, opt_db);
|
||||
@@ -5058,6 +5101,9 @@ void do_connect(struct st_command *command)
|
||||
dynstr_free(&ds_port);
|
||||
dynstr_free(&ds_sock);
|
||||
dynstr_free(&ds_options);
|
||||
#ifdef HAVE_SMEM
|
||||
dynstr_free(&ds_shm);
|
||||
#endif
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
@@ -5724,6 +5770,12 @@ static struct my_option my_long_options[] =
|
||||
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"server-file", 'F', "Read embedded server arguments from file.",
|
||||
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
||||
#ifdef HAVE_SMEM
|
||||
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
|
||||
"Base name of shared memory.", (uchar**) &shared_memory_base_name,
|
||||
(uchar**) &shared_memory_base_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
|
||||
0, 0, 0},
|
||||
#endif
|
||||
{"silent", 's', "Suppress all normal output. Synonym for --quiet.",
|
||||
(uchar**) &silent, (uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"skip-safemalloc", OPT_SKIP_SAFEMALLOC,
|
||||
@@ -7673,6 +7725,11 @@ int main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SMEM
|
||||
if (shared_memory_base_name)
|
||||
mysql_options(&con->mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
|
||||
#endif
|
||||
|
||||
if (!(con->name = my_strdup("default", MYF(MY_WME))))
|
||||
die("Out of memory");
|
||||
|
||||
|
Reference in New Issue
Block a user