pull/644/head
Mr Chen 5 months ago
parent aeb0f866c8
commit 43e69909cd
  1. 32
      plugins/mysql-apt/index.py
  2. 10
      plugins/mysql-apt/index_mysql_apt.py
  3. 27
      plugins/mysql-apt/versions/8.4/install_generic.sh

@ -416,7 +416,7 @@ def initMysql57Data():
myconf = serverdir + "/etc/my.cnf" myconf = serverdir + "/etc/my.cnf"
user = pGetDbUser() user = pGetDbUser()
cmd = serverdir + '/bin/usr/sbin/mysqld --basedir=' + serverdir + '/bin/usr --datadir=' + \ cmd = serverdir + '/bin/mysqld --basedir=' + serverdir + ' --datadir=' + \
datadir + ' --initialize-insecure --explicit_defaults_for_timestamp' datadir + ' --initialize-insecure --explicit_defaults_for_timestamp'
data = mw.execShell(cmd) data = mw.execShell(cmd)
if data[1].lower().find('error') != -1: if data[1].lower().find('error') != -1:
@ -444,7 +444,7 @@ def initMysql8Data():
serverdir = getServerDir() serverdir = getServerDir()
user = pGetDbUser() user = pGetDbUser()
cmd = serverdir + '/bin/usr/sbin/mysqld --basedir=' + serverdir + '/bin/usr --datadir=' + datadir + \ cmd = serverdir + '/bin/mysqld --basedir=' + serverdir + ' --datadir=' + datadir + \
' --initialize-insecure --lower-case-table-names=1' ' --initialize-insecure --lower-case-table-names=1'
data = mw.execShell(cmd) data = mw.execShell(cmd)
if data[1].lower().find('error') != -1: if data[1].lower().find('error') != -1:
@ -470,7 +470,7 @@ def initMysql8Pwd():
myconf = serverdir + "/etc/my.cnf" myconf = serverdir + "/etc/my.cnf"
pwd = mw.getRandomString(16) pwd = mw.getRandomString(16)
cmd_my = serverdir + '/bin/usr/bin/mysql' cmd_my = serverdir + '/bin/mysql'
cmd_pass = cmd_my + ' --defaults-file=' + myconf + ' -uroot -e' cmd_pass = cmd_my + ' --defaults-file=' + myconf + ' -uroot -e'
cmd_pass = cmd_pass + '"alter user \'root\'@\'localhost\' identified by \'' + pwd + '\';' cmd_pass = cmd_pass + '"alter user \'root\'@\'localhost\' identified by \'' + pwd + '\';'
@ -494,12 +494,10 @@ def initMysql8Pwd():
# 删除冗余账户 # 删除冗余账户
hostname = mw.execShell('hostname')[0].strip() hostname = mw.execShell('hostname')[0].strip()
if hostname != 'localhost': if hostname != 'localhost':
drop_hostname = cmd_my + ' --defaults-file=' + \ drop_hostname = cmd_my + ' --defaults-file=' + myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";'
myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";'
mw.execShell(drop_hostname) mw.execShell(drop_hostname)
drop_root_hostname = cmd_my + ' --defaults-file=' + \ drop_root_hostname = cmd_my + ' --defaults-file=' + myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";'
myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";'
mw.execShell(drop_root_hostname) mw.execShell(drop_root_hostname)
return True return True
@ -898,7 +896,7 @@ def importDbExternal():
sock = getSocketFile() sock = getSocketFile()
os.environ["MYSQL_PWD"] = pwd os.environ["MYSQL_PWD"] = pwd
mysql_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + ' -uroot -p' + \ mysql_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + \
pwd + ' ' + name + ' < ' + import_sql pwd + ' ' + name + ' < ' + import_sql
# print(mysql_cmd) # print(mysql_cmd)
@ -984,7 +982,7 @@ def importDbExternalProgressBar():
# option = ' --set-gtid-purged=off ' # option = ' --set-gtid-purged=off '
my_cnf = getConf() my_cnf = getConf()
mysql_cmd = getServerDir() + '/bin/usr/bin/mysql --defaults-file=' + my_cnf + \ mysql_cmd = getServerDir() + '/bin/mysql --defaults-file=' + my_cnf + \
' -uroot -p"' + pwd + '" -f ' + name ' -uroot -p"' + pwd + '" -f ' + name
mysql_cmd_progress_bar = "pv -t -p " + import_sql + '|'+ mysql_cmd mysql_cmd_progress_bar = "pv -t -p " + import_sql + '|'+ mysql_cmd
print(mysql_cmd_progress_bar) print(mysql_cmd_progress_bar)
@ -1009,7 +1007,7 @@ def importDbBackup():
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
sock = getSocketFile() sock = getSocketFile()
mysql_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \ mysql_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
' ' + name + ' < ' + file_path_sql ' ' + name + ' < ' + file_path_sql
# print(mysql_cmd) # print(mysql_cmd)
@ -1514,7 +1512,7 @@ def resetDbRootPwd(version):
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
mdb8 = getMdb8Ver() mdb8 = getMdb8Ver()
if not mw.inArray(mdb8, version): if not mw.inArray(mdb8, version):
cmd_pass = serverdir + '/bin/usr/bin/mysql --defaults-file=' + myconf + ' -uroot -e' cmd_pass = serverdir + '/bin/mysql --defaults-file=' + myconf + ' -uroot -e'
cmd_pass = cmd_pass + '"UPDATE mysql.user SET password=PASSWORD(\'' + pwd + "') WHERE user='root';" cmd_pass = cmd_pass + '"UPDATE mysql.user SET password=PASSWORD(\'' + pwd + "') WHERE user='root';"
cmd_pass = cmd_pass + 'flush privileges;"' cmd_pass = cmd_pass + 'flush privileges;"'
data = mw.execShell(cmd_pass) data = mw.execShell(cmd_pass)
@ -1534,7 +1532,7 @@ def resetDbRootPwd(version):
tmp_file = "/tmp/mysql_init_tmp.log" tmp_file = "/tmp/mysql_init_tmp.log"
mw.writeFile(tmp_file, reset_pwd) mw.writeFile(tmp_file, reset_pwd)
cmd_pass = serverdir + '/bin/usr/bin/mysql --defaults-file=' + myconf + ' -uroot -proot < ' + tmp_file cmd_pass = serverdir + '/bin/mysql --defaults-file=' + myconf + ' -uroot -proot < ' + tmp_file
data = mw.execShell(cmd_pass) data = mw.execShell(cmd_pass)
# print(data) # print(data)
@ -3245,7 +3243,7 @@ def doFullSyncUser(version=''):
dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port --compress " dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port --compress "
dump_sql_data = getServerDir() + "/bin/usr/bin/mysqldump --single-transaction --default-character-set=utf8mb4 -q " + dmp_option + " -h" + \ dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 -q " + dmp_option + " -h" + \
ip + " -P" + port + " -u" + user + ' -p"' + apass + '" --ssl-mode=DISABLED ' + sync_db + " > " + bak_file ip + " -P" + port + " -u" + user + ' -p"' + apass + '" --ssl-mode=DISABLED ' + sync_db + " > " + bak_file
print(dump_sql_data) print(dump_sql_data)
time_s = time.time() time_s = time.time()
@ -3276,16 +3274,16 @@ def doFullSyncUser(version=''):
sock = getSocketFile() sock = getSocketFile()
if is_exist_pv: if is_exist_pv:
my_import_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + " -uroot -p'" + pwd + "' " + sync_db_import my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + "' " + sync_db_import
my_import_cmd = "pv -t -p " + bak_file + '|' + my_import_cmd my_import_cmd = "pv -t -p " + bak_file + '|' + my_import_cmd
print(my_import_cmd) print(my_import_cmd)
os.system(my_import_cmd) os.system(my_import_cmd)
else: else:
my_import_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + " -uroot -p'" + pwd + "' " + sync_db_import + ' < ' + bak_file my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + "' " + sync_db_import + ' < ' + bak_file
print(my_import_cmd) print(my_import_cmd)
mw.execShell(my_import_cmd) mw.execShell(my_import_cmd)
my_import_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \ my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
' ' + sync_db_import + ' < ' + bak_file ' ' + sync_db_import + ' < ' + bak_file
mw.execShell(my_import_cmd) mw.execShell(my_import_cmd)
@ -3420,7 +3418,7 @@ def doFullSyncSSH(version=''):
root_dir = getServerDir() root_dir = getServerDir()
msock = root_dir + "/mysql.sock" msock = root_dir + "/mysql.sock"
mw.execShell("cd /tmp && gzip -d dump.sql.gz") mw.execShell("cd /tmp && gzip -d dump.sql.gz")
cmd = root_dir + "/bin/usr/bin/mysql -S " + msock + \ cmd = root_dir + "/bin/mysql -S " + msock + \
" -uroot -p" + pwd + " < /tmp/dump.sql" " -uroot -p" + pwd + " < /tmp/dump.sql"
print(cmd) print(cmd)

@ -15,11 +15,11 @@ if os.path.exists(web_dir):
import core.mw as mw import core.mw as mw
if mw.isAppleSystem(): # if mw.isAppleSystem():
cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' # cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\''
info = mw.execShell(cmd) # info = mw.execShell(cmd)
p = "/usr/local/lib/" + info[0].strip() + "/site-packages" # p = "/usr/local/lib/" + info[0].strip() + "/site-packages"
sys.path.append(p) # sys.path.append(p)
app_debug = False app_debug = False

@ -27,6 +27,12 @@ if [ "$OSNAME" == 'debian' ] && [ "$VERSION_ID" -lt '12' ] ;then
fi fi
# /lib/systemd/system/mysql.service
# /etc/mysql/my.cnf
APT_INSTALL()
{
ARCH="amd64" ARCH="amd64"
TMP_ARCH=`arch` TMP_ARCH=`arch`
if [ "$TMP_ARCH" == "x86_64" ];then if [ "$TMP_ARCH" == "x86_64" ];then
@ -44,32 +50,25 @@ fi
MYSQL_VER=8.4.2 MYSQL_VER=8.4.2
SUFFIX_NAME=${MYSQL_VER}-linux-glibc2.28_${TMP_ARCH} SUFFIX_NAME=${MYSQL_VER}-linux-glibc2.28-${TMP_ARCH}
# /lib/systemd/system/mysql.service
# /etc/mysql/my.cnf
APT_INSTALL()
{
######## ########
mkdir -p $myDir mkdir -p $myDir
mkdir -p $serverPath/mysql-apt/bin mkdir -p $serverPath/mysql-apt
mkdir -p /var/run/mysqld
chown mysql -R /var/run/mysqld
# Linux - Generic # Linux - Generic
# https://cdn.mysql.com/archives/mysql-8.4/mysql-8.4.2-linux-glibc2.28-x86_64.tar.xz # https://cdn.mysql.com/archives/mysql-8.4/mysql-8.4.2-linux-glibc2.28-x86_64.tar.xz
if [ ! -f ${myDir}/mysql-${SUFFIX_NAME}.tar.xz ];then
wget --no-check-certificate -O ${myDir}/mysql-${SUFFIX_NAME}.tar.xz https://cdn.mysql.com/archives/mysql-8.4/mysql-${SUFFIX_NAME}.tar.xz wget --no-check-certificate -O ${myDir}/mysql-${SUFFIX_NAME}.tar.xz https://cdn.mysql.com/archives/mysql-8.4/mysql-${SUFFIX_NAME}.tar.xz
fi
if [ -d ${myDir} ];then if [ -d ${myDir} ];then
cd ${myDir} && tar zvxf ${myDir}/mysql-${SUFFIX_NAME}.tar.xz cd ${myDir} && tar -Jxf ${myDir}/mysql-${SUFFIX_NAME}.tar.xz
cp -rf ${myDir}/mysql-${SUFFIX_NAME}/* $serverPath/mysql-apt
fi fi
# 测试时可关闭 # 测试时可关闭
rm -rf $myDir rm -rf $myDir/mysql-${SUFFIX_NAME}
####### #######
} }

Loading…
Cancel
Save