|
38 | 38 | from mysql.utilities.common.user import User
|
39 | 39 | from mysql.utilities.common.server import (get_server_state, get_server,
|
40 | 40 | get_connection_dictionary,
|
41 |
| - log_server_version) |
| 41 | + log_server_version, Server) |
42 | 42 | from mysql.utilities.common.messages import USER_PASSWORD_FORMAT
|
43 | 43 |
|
44 | 44 |
|
|
53 | 53 | _GTID_SUBTRACT_TO_EXECUTED = ("SELECT GTID_SUBTRACT('{0}', "
|
54 | 54 | "@@GLOBAL.GTID_EXECUTED)")
|
55 | 55 |
|
56 |
| -# TODO: Remove the use of PASSWORD(), depercated from 5.7.6. |
57 | 56 | _UPDATE_RPL_USER_QUERY = ("UPDATE mysql.user "
|
58 | 57 | "SET password = PASSWORD('{passwd}')"
|
59 | 58 | "where user ='{user}'")
|
60 | 59 | # Query for server versions >= 5.7.6.
|
61 | 60 | _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}'") |
64 | 62 |
|
65 | 63 | _SELECT_RPL_USER_PASS_QUERY = ("SELECT user, host, grant_priv, password, "
|
66 | 64 | "Repl_slave_priv FROM mysql.user "
|
@@ -1845,39 +1843,61 @@ def switchover(self, candidate):
|
1845 | 1843 | passwd_hash = passwd_hash[0][3]
|
1846 | 1844 | else:
|
1847 | 1845 | 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 |
1861 | 1872 | 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 |
1869 | 1882 | # Use the correct query for server (changed for 5.7.6).
|
| 1883 | + self.master.toggle_binlog("DISABLE") |
1870 | 1884 | if self.master.check_version_compat(5, 7, 6):
|
1871 | 1885 | 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)) |
1872 | 1889 | else:
|
1873 | 1890 | 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") |
1875 | 1893 |
|
1876 | 1894 | if self.verbose:
|
1877 | 1895 | self._report("# Creating replication user if it does not exist.")
|
| 1896 | + self.master.toggle_binlog("DISABLE") |
1878 | 1897 | res = m_candidate.create_rpl_user(m_candidate.host,
|
1879 | 1898 | m_candidate.port,
|
1880 | 1899 | user, passwd, ssl=self.ssl)
|
| 1900 | + self.master.toggle_binlog("ENABLE") |
1881 | 1901 | if not res[0]:
|
1882 | 1902 | print("# ERROR: {0}".format(res[1]))
|
1883 | 1903 | self._report(res[1], logging.CRITICAL, False)
|
|
0 commit comments