From 9ea52e452a863eef73e5d772b58f826132c35c9f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 14 Dec 2023 00:04:48 +0800 Subject: [PATCH] =?UTF-8?q?mysql=E8=AF=86=E5=88=AB=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mysql/conf/my8.0.cnf | 1 - plugins/mysql/index.py | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index 79a3bed0c..8ccfde4fe 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -10,7 +10,6 @@ default-character-set = UTF8MB4 sha256_password_private_key_path={$SERVER_APP_PATH}/data/mysql.pem sha256_password_public_key_path={$SERVER_APP_PATH}/data/mysql.pub -#authentication_policy=caching_sha2_password authentication_policy=mysql_native_password pid-file = {$SERVER_APP_PATH}/data/mysql.pid diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 2e091d43f..87329ea90 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -116,6 +116,16 @@ def getErrorLogsFile(): tmp = re.search(rep, content) return tmp.groups()[0].strip() +def getAuthPolicy(): + file = getConf() + content = mw.readFile(file) + rep = 'authentication_policy\s*=\s*(.*)' + tmp = re.search(rep, content) + if tmp: + return tmp.groups()[0].strip() + # caching_sha2_password + return 'mysql_native_password' + def getInitdTpl(version=''): path = getPluginDir() + '/init.d/mysql' + version + '.tpl' @@ -530,6 +540,9 @@ def initMysqlPwd(): def initMysql8Pwd(): time.sleep(8) + + auth_policy = getAuthPolicy() + serverdir = getServerDir() myconf = serverdir + "/etc/my.cnf" @@ -543,7 +556,7 @@ def initMysql8Pwd(): alter_root_pwd = alter_root_pwd + \ "alter user 'root'@'localhost' IDENTIFIED by '" + pwd + "';" alter_root_pwd = alter_root_pwd + \ - "alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '" + pwd + "';" + "alter user 'root'@'localhost' IDENTIFIED WITH "+auth_policy+" by '" + pwd + "';" alter_root_pwd = alter_root_pwd + "flush privileges;" cmd_pass = serverdir + '/bin/mysqladmin --defaults-file=' + \ @@ -2125,12 +2138,14 @@ def addMasterRepSlaveUser(version=''): pdb = pMysqlDb() psdb = pSqliteDb('master_replication_user') + auth_policy = getAuthPolicy() + if psdb.where("username=?", (username)).count() > 0: return mw.returnJson(False, '用户已存在!') if version == "8.0": sql = "CREATE USER '" + username + \ - "' IDENTIFIED WITH mysql_native_password BY '" + password + "';" + "' IDENTIFIED WITH "+auth_policy+" BY '" + password + "';" pdb.execute(sql) sql = "grant replication slave on *.* to '" + username + "'@'%';" result = pdb.execute(sql)