代码恢复

This commit is contained in:
midoks
2022-06-28 09:18:17 +08:00
parent af32792bf1
commit fbac71e542
111 changed files with 1576 additions and 973 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ class mysqlDb:
'''连接MYSQL数据库'''
try:
import mw
socket = '/tmp/mysql.sock'
socket = '/www/server/mysql/mysql.sock'
try:
import MySQLdb
except Exception as ex:
+1 -1
View File
@@ -80,7 +80,7 @@ innodb_write_io_threads = 1
innodb_file_per_table=1
secure-file-priv=/tmp
secure-file-priv={$SERVER_APP_PATH}/tmp
[mysqldump]
quick
+1 -1
View File
@@ -76,7 +76,7 @@ innodb_read_io_threads = 1
innodb_write_io_threads = 1
innodb_file_per_table=1
secure-file-priv=/tmp
secure-file-priv={$SERVER_APP_PATH}/tmp
[mysqldump]
quick
+1 -1
View File
@@ -77,7 +77,7 @@ innodb_write_io_threads = 1
innodb_file_per_table=1
binlog_expire_logs_seconds=2592000
secure-file-priv=/tmp
secure-file-priv={$SERVER_APP_PATH}/tmp
[mysqldump]
quick
+63 -77
View File
@@ -103,6 +103,8 @@ def getConf():
def getInitdTpl(version=''):
path = getPluginDir() + '/init.d/mysql' + version + '.tpl'
if not os.path.exists(path):
path = getPluginDir() + '/init.d/mysql.tpl'
return path
@@ -161,6 +163,11 @@ def initDreplace(version=''):
if not os.path.exists(mysql_conf_dir):
os.mkdir(mysql_conf_dir)
mysql_tmp = getServerDir() + '/tmp'
if not os.path.exists(mysql_tmp):
os.mkdir(mysql_tmp)
mw.execShell("chown -R mysql:mysql " + mysql_tmp)
mysql_conf = mysql_conf_dir + '/my.cnf'
if not os.path.exists(mysql_conf):
mysql_conf_tpl = getPluginDir() + '/conf/my' + version + '.cnf'
@@ -291,8 +298,8 @@ def initMysqlData():
cmd = 'cd ' + serverdir + ' && ./scripts/mysql_install_db --user=' + \
user + ' --basedir=' + serverdir + ' --ldata=' + datadir
mw.execShell(cmd)
return 0
return 1
return False
return True
def initMysql57Data():
@@ -302,10 +309,10 @@ def initMysql57Data():
myconf = serverdir + "/etc/my.cnf"
user = pGetDbUser()
cmd = 'cd ' + serverdir + ' && ./bin/mysqld --defaults-file=' + myconf + \
' --initialize --explicit_defaults_for_timestamp'
' --initialize-insecure --explicit_defaults_for_timestamp'
mw.execShell(cmd)
return 0
return 1
return False
return True
def initMysql8Data():
@@ -313,12 +320,16 @@ def initMysql8Data():
if not os.path.exists(datadir + '/mysql'):
serverdir = getServerDir()
user = pGetDbUser()
# cmd = 'cd ' + serverdir + ' && ./bin/mysqld --basedir=' + serverdir + ' --datadir=' + \
# datadir + ' --initialize'
cmd = 'cd ' + serverdir + ' && ./bin/mysqld --basedir=' + serverdir + ' --datadir=' + \
datadir + ' --initialize'
datadir + ' --initialize-insecure'
# print(cmd)
mw.execShell(cmd)
return 0
return 1
return False
return True
def initMysqlPwd():
@@ -328,8 +339,8 @@ def initMysqlPwd():
pwd = mw.getRandomString(16)
cmd_pass = serverdir + '/bin/mysqladmin -uroot password ' + pwd
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
mw.execShell(cmd_pass)
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
return True
@@ -347,62 +358,29 @@ def mysql8IsInitedPasswd():
def initMysql8Pwd():
is_start = False
for x in range(60):
data = mw.execShell(
"ps -ef|grep mysql|grep -v grep|grep -v py|grep -v init.d|awk '{print $2}'")
if data[0] != "":
# print("mysql start ok!")
is_start = True
break
time.sleep(0.5)
if not is_start:
# print("mysql start fail!")
return False
time.sleep(2)
serverdir = getServerDir()
pwd = mw.getRandomString(16)
pass_cmd = "cat " + serverdir + \
"/data/error.log | grep root@localhost | awk -F 'root@localhost:' '{print $2}'"
passdata = mw.execShell(pass_cmd)
password = passdata[0].strip()
if len(password) == 0:
return True
# print('localhost', 3306, 'root', password,
# "/www/server/mysql/mysql.sock")
# import MySQLdb as mdb
# dbconn = mdb.connect(host='localhost', port=3306, user='root',
# passwd=password, unix_socket="/www/server/mysql/mysql.sock")
# dbconn.autocommit(True)
# dbcurr = dbconn.cursor()
# dbcurr.execute('SET NAMES UTF8MB4')
# # with mysql_native_password
alter_root_pwd = 'flush privileges;'
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_root_pwd = alter_root_pwd + "flush privileges;"
# dbcurr.execute(alter_root_pwd)
cmd_pass = serverdir + '/bin/mysqladmin -uroot password root'
data = mw.execShell(cmd_pass)
# print(data)
tmp_file = "/tmp/mysql_init_tmp.log"
mw.writeFile(tmp_file, alter_root_pwd)
cmd_pass = serverdir + '/bin/mysql --connect-expired-password -uroot -p"' + \
password + '" < ' + tmp_file
# print(cmd_pass)
cmd_pass = serverdir + '/bin/mysql -uroot -proot < ' + tmp_file
data = mw.execShell(cmd_pass)
if data[1].find("ERROR") != -1:
# print(data[1])
pass
else:
mw.writeFile(serverdir + "/data/error.log", "")
os.remove(tmp_file)
# print(data)
os.remove(tmp_file)
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
@@ -413,9 +391,11 @@ def myOp(version, method):
# import commands
init_file = initDreplace()
try:
initData = initMysqlData()
if initData == 0:
isInited = initMysqlData()
if not isInited:
mw.execShell('systemctl start mysql')
initMysqlPwd()
mw.execShell('systemctl stop mysql')
mw.execShell('systemctl ' + method + ' mysql')
return 'ok'
@@ -424,39 +404,46 @@ def myOp(version, method):
def my8cmd(version, method):
# mysql 8.0 and 5.7 ok
# mysql 8.0 and 5.7
init_file = initDreplace(version)
if version == '5.7':
initMysql57Data()
elif version == '8.0':
initMysql8Data()
cmd = init_file + ' ' + method
try:
if version == '5.7':
isInited = initMysql57Data()
elif version == '8.0':
isInited = initMysql8Data()
if not mysql8IsInitedPasswd():
setSkipGrantTables(True)
cmd_init_start = init_file + ' start'
subprocess.Popen(cmd_init_start, stdout=subprocess.PIPE, shell=True,
bufsize=4096, stderr=subprocess.PIPE)
if not isInited:
if mw.isAppleSystem():
cmd_init_start = init_file + ' start'
subprocess.Popen(cmd_init_start, stdout=subprocess.PIPE, shell=True,
bufsize=4096, stderr=subprocess.PIPE)
time.sleep(6)
else:
mw.execShell('systemctl start mysql')
time.sleep(6)
initMysql8Pwd()
cmd_init_stop = init_file + ' stop'
subprocess.Popen(cmd_init_stop, stdout=subprocess.PIPE, shell=True,
bufsize=4096, stderr=subprocess.PIPE)
setSkipGrantTables(False)
if mw.isAppleSystem():
cmd_init_stop = init_file + ' stop'
subprocess.Popen(cmd_init_stop, stdout=subprocess.PIPE, shell=True,
bufsize=4096, stderr=subprocess.PIPE)
time.sleep(3)
else:
mw.execShell('systemctl stop mysql')
time.sleep(3)
my8cmd(version, method)
if mw.isAppleSystem():
sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True,
bufsize=4096, stderr=subprocess.PIPE)
sub.wait(5)
else:
mw.execShell('systemctl ' + method + ' mysql')
return 'ok'
except Exception as e:
return str(e)
return 'fail'
def appCMD(version, action):
if version == '8.0' or version == '5.7':
@@ -481,9 +468,8 @@ def reload(version=''):
def initdStatus():
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
if mw.isAppleSystem():
return "Apple Computer does not support"
shell_cmd = 'systemctl status mysql | grep loaded | grep "enabled;"'
data = mw.execShell(shell_cmd)
@@ -673,7 +659,7 @@ def isSqlError(mysqlMsg):
# 检测数据库执行错误
mysqlMsg = str(mysqlMsg)
if "MySQLdb" in mysqlMsg:
return mw.returnJson(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
return mw.returnJson(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python | pip install mysqlclient==2.0.3')
if "2002," in mysqlMsg:
return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
if "2003," in mysqlMsg:
+23 -9
View File
@@ -805,6 +805,8 @@ function setDbPs(id, name, obj) {
function openPhpmyadmin(name,username,password){
data = syncPost('/plugins/check',{'name':'phpmyadmin'});
if (!data.status){
layer.msg(data.msg,{icon:2,shade: [0.3, '#000']});
return;
@@ -815,7 +817,7 @@ function openPhpmyadmin(name,username,password){
layer.msg('phpMyAdmin未启动',{icon:2,shade: [0.3, '#000']});
return;
}
// console.log(data);
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'get_home_page'});
var rdata = $.parseJSON(data.data);
if (!rdata.status){
@@ -830,16 +832,28 @@ function openPhpmyadmin(name,username,password){
return;
}
var murl = $("#toPHPMyAdmin").attr('action');
$("#pma_username").val(username);
$("#pma_password").val(password);
$("#db").val(name);
//检查版本
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'version'});
bigVer = data.data.split('.')[0]
if (bigVer>=5){
layer.msg('正在打开phpMyAdmin',{icon:16,shade: [0.3, '#000'],time:1000});
setTimeout(function(){
$("#toPHPMyAdmin").submit();
},3000);
layer.msg('phpMyAdmin['+data.data+']需要手动登录😭',{icon:16,shade: [0.3, '#000'],time:4000});
} else{
var murl = $("#toPHPMyAdmin").attr('action');
$("#pma_username").val(username);
$("#pma_password").val(password);
$("#db").val(name);
setTimeout(function(){
$("#toPHPMyAdmin").submit();
},2000);
layer.msg('正在打开phpMyAdmin',{icon:16,shade: [0.3, '#000'],time:2000});
setTimeout(function(){
$("#toPHPMyAdmin").submit();
},3000);
}
}
function delBackup(filename,name){
+21 -7
View File
@@ -14,16 +14,23 @@ sysName=`uname`
install_tmp=${rootPath}/tmp/mw_install.pl
mysqlDir=${serverPath}/source/mysql
Install_mysql()
{
mkdir -p ${mysqlDir}
echo '正在安装脚本文件...' > $install_tmp
if id mysql &> /dev/null ;then
echo "mysql UID is `id -u www`"
echo "mysql Shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
else
groupadd mysql
useradd -g mysql mysql
fi
if [ "$sysName" != "Darwin" ];then
mkdir -p /var/log/mariadb
touch /var/log/mariadb/mariadb.log
groupadd mysql
useradd -g mysql mysql
fi
if [ ! -f ${mysqlDir}/mysql-5.5.62.tar.gz ];then
@@ -47,11 +54,18 @@ Install_mysql()
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
&& make && make install && make clean \
&& echo '5.5' > $serverPath/mysql/version.pl
echo '安装完成' > $install_tmp
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
&& make ${MAKEJN:--j2} && make install && make clean
if [ -d $serverPath/mysql ];then
echo '5.5' > $serverPath/mysql/version.pl
echo '安装完成' > $install_tmp
else
echo '安装失败' > $install_tmp
fi
fi
}
+22 -7
View File
@@ -17,16 +17,23 @@ sysName=`uname`
install_tmp=${rootPath}/tmp/mw_install.pl
mysqlDir=${serverPath}/source/mysql
Install_mysql()
{
mkdir -p ${mysqlDir}
echo '正在安装脚本文件...' > $install_tmp
if id mysql &> /dev/null ;then
echo "mysql UID is `id -u www`"
echo "mysql Shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
else
groupadd mysql
useradd -g mysql mysql
fi
if [ "$sysName" != "Darwin" ];then
mkdir -p /var/log/mariadb
touch /var/log/mariadb/mariadb.log
groupadd mysql
useradd -g mysql mysql
fi
@@ -51,11 +58,19 @@ Install_mysql()
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
&& make && make install && make clean
echo '5.6' > $serverPath/mysql/version.pl
echo '安装完成' > $install_tmp
-DDEFAULT_CHARSET=utf8mb4 \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
&& make ${MAKEJN:--j2} && make install && make clean
if [ -d $serverPath/mysql ];then
echo '5.6' > $serverPath/mysql/version.pl
echo '安装完成' > $install_tmp
else
echo '安装失败' > $install_tmp
fi
fi
}
+29 -6
View File
@@ -19,22 +19,43 @@ mysqlDir=${serverPath}/source/mysql
VERSION="5.7.37"
Install_mysql()
{
mkdir -p ${mysqlDir}
echo '正在安装脚本文件...' > $install_tmp
if id mysql &> /dev/null ;then
echo "mysql UID is `id -u www`"
echo "mysql Shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
else
groupadd mysql
useradd -g mysql mysql
fi
if [ "$sysName" != "Darwin" ];then
mkdir -p /var/log/mariadb
touch /var/log/mariadb/mariadb.log
groupadd mysql
useradd -g mysql mysql
fi
fi
if [ ! -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-${VERSION}.tar.gz
fi
#检测文件是否损坏.
md5_mysql_ok=d0489fc3880248a58759c50bfb286dbb
if [ -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
md5_mysql=`md5sum ${mysqlDir}/mysql-boost-${VERSION}.tar.gz | awk '{print $1}'`
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
echo "mysql5.7 file check ok"
else
# 重新下载
rm -rf ${mysqlDir}/mysql-${VERSION}
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-${VERSION}.tar.gz
fi
fi
if [ ! -d ${mysqlDir}/mysql-${VERSION} ];then
cd ${mysqlDir} && tar -zxvf ${mysqlDir}/mysql-boost-${VERSION}.tar.gz
fi
@@ -51,11 +72,13 @@ Install_mysql()
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DDOWNLOAD_BOOST=1 \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DWITH_BOOST=${mysqlDir}/mysql-${VERSION}/boost/
make && make install && make clean
make ${MAKEJN:--j2} && make install && make clean
echo '5.7' > $serverPath/mysql/version.pl
echo '安装完成' > $install_tmp
fi
+34 -7
View File
@@ -1,3 +1,5 @@
export MAKEJN=-j12
# -*- coding: utf-8 -*-
#!/bin/bash
@@ -22,13 +24,19 @@ Install_mysql()
mkdir -p ${mysqlDir}
echo '正在安装脚本文件...' > $install_tmp
if id mysql &> /dev/null ;then
echo "mysql UID is `id -u www`"
echo "mysql Shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
else
groupadd mysql
useradd -g mysql mysql
fi
INSTALL_CMD=cmake
if [ "$sysName" != "Darwin" ];then
mkdir -p /var/log/mariadb
touch /var/log/mariadb/mariadb.log
groupadd mysql
useradd -g mysql mysql
INSTALL_CMD=cmake
fi
@@ -36,10 +44,24 @@ Install_mysql()
wget -O ${mysqlDir}/mysql-boost-8.0.25.tar.gz https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-8.0.25.tar.gz
fi
#检测文件是否损坏.
md5_mysql_ok=e142c2058313b4646c36fa9bb1b38493
if [ -f ${mysqlDir}/mysql-boost-8.0.25.tar.gz ];then
md5_mysql=`md5sum ${mysqlDir}/mysql-boost-8.0.25.tar.gz | awk '{print $1}'`
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
echo "mysql8.0 file check ok"
else
# 重新下载
rm -rf ${mysqlDir}/mysql-8.0.25
wget -O ${mysqlDir}/mysql-boost-8.0.25.tar.gz https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-8.0.25.tar.gz
fi
fi
if [ ! -d ${mysqlDir}/mysql-8.0.25 ];then
cd ${mysqlDir} && tar -zxvf ${mysqlDir}/mysql-boost-8.0.25.tar.gz
fi
if [ ! -d $serverPath/mysql ];then
cd ${mysqlDir}/mysql-8.0.25 && ${INSTALL_CMD} \
-DCMAKE_INSTALL_PREFIX=$serverPath/mysql \
@@ -52,13 +74,18 @@ Install_mysql()
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DDOWNLOAD_BOOST=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DWITH_BOOST=${mysqlDir}/mysql-8.0.25/boost/
make && make install && make clean
echo '8.0' > $serverPath/mysql/version.pl
make ${MAKEJN:--j2} && make install && make clean
if [ -d $serverPath/mysql ];then
echo '8.0' > $serverPath/mysql/version.pl
fi
echo '安装完成' > $install_tmp
fi
}