Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit f0fd574

Browse files
author
Chuck Bell
committed
BUG#20807296 : remove use password() function (deprecated as of mysql 5.7.6)
The code currently uses the password() function, which was deprecated in version 5.7.6. This must be remove or else the utilities will crash when used with newer servers. This patch removes the use of the password() function when run with server version 5.7.6 or later. CAB v3
1 parent b80178f commit f0fd574

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

mysql-test/suite/replication/r/rpl_admin_gtid_demote_master_repo_file.result

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,9 @@ Test case 9 - demote-master switchover -vvv Using a different rpl user and using
214214
# Slave XXXXXXXXX:PORT1:
215215
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(XXXXX)
216216
# Return Code = NNN
217-
# Slave XXXXXXXXX:PORT1:
218-
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(XXXXX)
219-
# Return Code = NNN
220217
# Slave XXXXXXXXX:PORT3:
221218
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(XXXXX)
222219
# Return Code = NNN
223-
# Slave XXXXXXXXX:PORT3:
224-
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(XXXXX)
225-
# Return Code = NNN
226-
# Slave XXXXXXXXX:PORT4:
227-
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(XXXXX)
228-
# Return Code = NNN
229220
# Slave XXXXXXXXX:PORT4:
230221
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(XXXXX)
231222
# Return Code = NNN

mysql/utilities/common/topology.py

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from mysql.utilities.common.user import User
3939
from mysql.utilities.common.server import (get_server_state, get_server,
4040
get_connection_dictionary,
41-
log_server_version)
41+
log_server_version, Server)
4242
from mysql.utilities.common.messages import USER_PASSWORD_FORMAT
4343

4444

@@ -53,14 +53,12 @@
5353
_GTID_SUBTRACT_TO_EXECUTED = ("SELECT GTID_SUBTRACT('{0}', "
5454
"@@GLOBAL.GTID_EXECUTED)")
5555

56-
# TODO: Remove the use of PASSWORD(), depercated from 5.7.6.
5756
_UPDATE_RPL_USER_QUERY = ("UPDATE mysql.user "
5857
"SET password = PASSWORD('{passwd}')"
5958
"where user ='{user}'")
6059
# Query for server versions >= 5.7.6.
6160
_UPDATE_RPL_USER_QUERY_5_7_6 = (
62-
"UPDATE mysql.user SET authentication_string = PASSWORD('{passwd}') "
63-
"WHERE user = '{user}'")
61+
"ALTER USER IF EXISTS '{user}'@'{host}' IDENTIFIED BY '{passwd}'")
6462

6563
_SELECT_RPL_USER_PASS_QUERY = ("SELECT user, host, grant_priv, password, "
6664
"Repl_slave_priv FROM mysql.user "
@@ -1845,39 +1843,61 @@ def switchover(self, candidate):
18451843
passwd_hash = passwd_hash[0][3]
18461844
else:
18471845
passwd_hash = ""
1848-
# now hash the given rpl password from --rpl-user.
1849-
# TODO: Remove the use of PASSWORD(), depercated from 5.7.6.
1850-
rpl_master_pass = slave_qry("SELECT PASSWORD('%s');" %
1851-
passwd)
1852-
rpl_master_pass = rpl_master_pass[0][0]
1853-
1854-
if (rpl_master_pass != passwd_hash):
1855-
if passwd == '':
1856-
msg = ("The specified replication user is using a "
1857-
"password (but none was specified).\n"
1858-
"Use the --force option to force the use of "
1859-
"the user specified with --rpl-user and no "
1860-
"password.")
1846+
if passwd == '':
1847+
msg = ("The specified replication user is using a "
1848+
"password (but none was specified).\n"
1849+
"Use the --force option to force the use of "
1850+
"the user specified with --rpl-user and no "
1851+
"password.")
1852+
else:
1853+
msg = ("The specified replication user is using a "
1854+
"different password that the one specified.\n"
1855+
"Use the --force option to force the use of "
1856+
"the user specified with --rpl-user and new "
1857+
"password.")
1858+
# If 5.7.6+, check by trying to connect
1859+
if self.master.check_version_compat(5, 7, 6):
1860+
config = {
1861+
'user': user,
1862+
'passwd': passwd,
1863+
'host': m_candidate.host,
1864+
'port': m_candidate.port,
1865+
}
1866+
s_conn = Server({'conn_info': config})
1867+
try:
1868+
s_conn.connect()
1869+
except:
1870+
self._report("ERROR: %s" % msg, logging.ERROR)
1871+
return
18611872
else:
1862-
msg = ("The specified replication user is using a "
1863-
"different password that the one specified.\n"
1864-
"Use the --force option to force the use of "
1865-
"the user specified with --rpl-user and new "
1866-
"password.")
1867-
self._report("ERROR: %s" % msg, logging.ERROR)
1868-
return
1873+
s_conn.disconnect()
1874+
# else compare the hash fom --rpl-user.
1875+
else:
1876+
rpl_master_pass = slave_qry("SELECT PASSWORD('%s');" %
1877+
passwd)
1878+
rpl_master_pass = rpl_master_pass[0][0]
1879+
if rpl_master_pass != passwd_hash:
1880+
self._report("ERROR: %s" % msg, logging.ERROR)
1881+
return
18691882
# Use the correct query for server (changed for 5.7.6).
1883+
self.master.toggle_binlog("DISABLE")
18701884
if self.master.check_version_compat(5, 7, 6):
18711885
query = _UPDATE_RPL_USER_QUERY_5_7_6
1886+
self.master.exec_query(query.format(user=user,
1887+
host=m_candidate.host,
1888+
passwd=passwd))
18721889
else:
18731890
query = _UPDATE_RPL_USER_QUERY
1874-
self.master.exec_query(query.format(user=user, passwd=passwd))
1891+
self.master.exec_query(query.format(user=user, passwd=passwd))
1892+
self.master.toggle_binlog("ENABLE")
18751893

18761894
if self.verbose:
18771895
self._report("# Creating replication user if it does not exist.")
1896+
self.master.toggle_binlog("DISABLE")
18781897
res = m_candidate.create_rpl_user(m_candidate.host,
18791898
m_candidate.port,
18801899
user, passwd, ssl=self.ssl)
1900+
self.master.toggle_binlog("ENABLE")
18811901
if not res[0]:
18821902
print("# ERROR: {0}".format(res[1]))
18831903
self._report(res[1], logging.CRITICAL, False)

0 commit comments

Comments
 (0)