summaryrefslogtreecommitdiff
path: root/client/mysql.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysql.cc')
-rw-r--r--client/mysql.cc77
1 files changed, 41 insertions, 36 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 71eac780262..f1346395dfe 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1346,6 +1346,44 @@ sig_handler mysql_end(int sig)
exit(status.exit_status);
}
+/*
+ set connection-specific options and call mysql_real_connect
+*/
+static bool do_connect(MYSQL *mysql, const char *host, const char *user,
+ const char *password, const char *database, ulong flags)
+{
+ if (opt_secure_auth)
+ mysql_options(mysql, MYSQL_SECURE_AUTH, (char *) &opt_secure_auth);
+#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
+ if (opt_use_ssl)
+ {
+ mysql_ssl_set(mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
+ opt_ssl_capath, opt_ssl_cipher);
+ mysql_options(mysql, MYSQL_OPT_SSL_CRL, opt_ssl_crl);
+ mysql_options(mysql, MYSQL_OPT_SSL_CRLPATH, opt_ssl_crlpath);
+ }
+ mysql_options(mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
+ (char*)&opt_ssl_verify_server_cert);
+#endif
+ if (opt_protocol)
+ mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
+#ifdef HAVE_SMEM
+ if (shared_memory_base_name)
+ mysql_options(mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
+#endif
+ if (opt_plugin_dir && *opt_plugin_dir)
+ mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);
+
+ if (opt_default_auth && *opt_default_auth)
+ mysql_options(mysql, MYSQL_DEFAULT_AUTH, opt_default_auth);
+
+ mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
+ mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
+ "program_name", "mysql");
+ return mysql_real_connect(mysql, host, user, password, database,
+ opt_mysql_port, opt_mysql_unix_port, flags);
+}
+
/*
This function handles sigint calls
@@ -1367,11 +1405,7 @@ sig_handler handle_sigint(int sig)
}
kill_mysql= mysql_init(kill_mysql);
- mysql_options(kill_mysql, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
- mysql_options4(kill_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
- "program_name", "mysql");
- if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
- "", opt_mysql_port, opt_mysql_unix_port,0))
+ if (!do_connect(kill_mysql,current_host, current_user, opt_password, "", 0))
{
tee_fprintf(stdout, "Ctrl-C -- sorry, cannot connect to server to kill query, giving up ...\n");
goto err;
@@ -4580,27 +4614,8 @@ sql_real_connect(char *host,char *database,char *user,char *password,
}
if (opt_compress)
mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
- if (opt_secure_auth)
- mysql_options(&mysql, MYSQL_SECURE_AUTH, (char *) &opt_secure_auth);
if (using_opt_local_infile)
mysql_options(&mysql,MYSQL_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
-#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
- if (opt_use_ssl)
- {
- mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
- opt_ssl_capath, opt_ssl_cipher);
- mysql_options(&mysql, MYSQL_OPT_SSL_CRL, opt_ssl_crl);
- mysql_options(&mysql, MYSQL_OPT_SSL_CRLPATH, opt_ssl_crlpath);
- }
- mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
- (char*)&opt_ssl_verify_server_cert);
-#endif
- if (opt_protocol)
- mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
-#ifdef HAVE_SMEM
- if (shared_memory_base_name)
- mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
-#endif
if (safe_updates)
{
char init_command[100];
@@ -4612,18 +4627,8 @@ sql_real_connect(char *host,char *database,char *user,char *password,
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
- if (opt_plugin_dir && *opt_plugin_dir)
- mysql_options(&mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);
-
- if (opt_default_auth && *opt_default_auth)
- mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth);
-
- mysql_options(&mysql, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
- mysql_options4(&mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
- "program_name", "mysql");
- if (!mysql_real_connect(&mysql, host, user, password,
- database, opt_mysql_port, opt_mysql_unix_port,
- connect_flag | CLIENT_MULTI_STATEMENTS))
+ if (!do_connect(&mysql, host, user, password, database,
+ connect_flag | CLIENT_MULTI_STATEMENTS))
{
if (!silent ||
(mysql_errno(&mysql) != CR_CONN_HOST_ERROR &&