MXS-2644 Log reason if mysql_real_connect fails

If mysql_real_connect fails inside any of the open_conn_db...
utility functions that will now be logged.
This commit is contained in:
Johan Wikman 2019-08-20 15:25:10 +03:00
parent 891d0503a0
commit e2124ec01f
2 changed files with 30 additions and 19 deletions

View File

@ -53,14 +53,20 @@ MYSQL* open_conn_db_flags(int port,
// MXS-2568: This fixes mxs1828_double_local_infile
mysql_optionsv(conn, MYSQL_OPT_LOCAL_INFILE, (void*)"1");
mysql_real_connect(conn,
ip.c_str(),
user.c_str(),
password.c_str(),
db.c_str(),
port,
NULL,
flag);
if (!mysql_real_connect(conn,
ip.c_str(),
user.c_str(),
password.c_str(),
db.c_str(),
port,
NULL,
flag))
{
fprintf(stdout,
"Could not connect to %s:%d with user '%s' and password '%s', "
"and default database '%s': %s\n",
ip.c_str(), port, user.c_str(), password.c_str(), db.c_str(), mysql_error(conn));
}
return conn;
}
@ -92,14 +98,20 @@ MYSQL* open_conn_db_timeout(int port,
set_ssl(conn);
}
mysql_real_connect(conn,
ip.c_str(),
user.c_str(),
password.c_str(),
db.c_str(),
port,
NULL,
CLIENT_MULTI_STATEMENTS);
if (!mysql_real_connect(conn,
ip.c_str(),
user.c_str(),
password.c_str(),
db.c_str(),
port,
NULL,
CLIENT_MULTI_STATEMENTS))
{
fprintf(stdout,
"Could not connect to %s:%d with user '%s' and password '%s', "
"and default database '%s': %s\n",
ip.c_str(), port, user.c_str(), password.c_str(), db.c_str(), mysql_error(conn));
}
return conn;
}

View File

@ -84,7 +84,7 @@ int Mariadb_nodes::connect(int i, const std::string& db)
nodes[i] = open_conn_db_timeout(port[i], IP[i], db.c_str(), user_name, password, 50, ssl);
}
if ((nodes[i] != NULL) && (mysql_errno(nodes[i]) != 0))
if ((nodes[i] == NULL) || (mysql_errno(nodes[i]) != 0))
{
return 1;
}
@ -1015,8 +1015,7 @@ bool do_flush_hosts(MYSQL* conn)
int Mariadb_nodes::flush_hosts()
{
if (this->nodes[0] == NULL && this->connect())
if (this->nodes[0] == NULL && (this->connect() != 0))
{
return 1;
}