Files
download/panel/mysql/update.sh
耗子 a65d23f05b
Some checks failed
Generate Checksums / checksums (push) Has been cancelled
feat: 移除协议
2025-08-22 06:19:40 +08:00

109 lines
3.4 KiB (Stored with Git LFS)
Bash

#!/bin/bash
source <(curl -f -s --connect-timeout 10 --retry 3 https://dl.cdn.haozi.net/panel/public.sh)
if [ $? -ne 0 ]; then
echo "下载 public.sh 失败,请检查网络或稍后重试。"
echo "Download public.sh failed, please check the network or try again later."
exit 1
fi
channel=${1}
version=${2}
mysql_path="${setup_path}/server/mysql"
mysql_password=$(panel-cli setting get mysql_root_password)
j=$(calculate_j)
# 预检查
systemctl is-active --quiet mysqld
if [ "$?" != "0" ]; then
error "应用运行状态不正常"
fi
# 准备目录
cd ${mysql_path}
rm -rf src
# 下载源码
wget --retry-connrefused --retry-on-host-error --retry-on-http-error=429,500,502,503,504 -t 10 -T 120 -O ${mysql_path}/percona-server-${version}.7z ${download_url}/mysql/percona-server-${version}.7z
wget --retry-connrefused --retry-on-host-error --retry-on-http-error=429,500,502,503,504 -t 10 -T 120 -O ${mysql_path}/percona-server-${version}.7z.sha256 ${download_url}/mysql/percona-server-${version}.7z.sha256
if ! sha256sum --status -c percona-server-${version}.7z.sha256; then
rm -f percona-server-${version}.7z
rm -f percona-server-${version}.7z.sha256
error "mysql 校验失败"
fi
7z x percona-server-${version}.7z
rm -f percona-server-${version}.7z
rm -f percona-server-${version}.7z.sha256
# 编译
mv percona-server-${version} src
chmod -R 700 src
cd src
mkdir dist
cd dist
# 57 和 80 需要 boost 和禁用 TOKUDB
if [[ ${channel} == "percona_57" ]] || [[ ${channel} == "percona_80" ]]; then
WITH_BOOST="-DWITH_BOOST=../boost"
WITHOUT_TOKUDB="-DWITH_TOKUDB=0"
fi
# 80+ 禁用 MYSQLX 和 ROUTER
WITHOUT_MYSQLX="-DWITH_MYSQLX=0"
WITHOUT_ROUTER="-DWITH_ROUTER=0"
if [[ ${channel} == "percona_57" ]]; then
WITHOUT_MYSQLX=""
WITHOUT_ROUTER=""
fi
# 内存小于 8G 禁用 RocksDB
WITH_ROCKSDB=1
if [ ${MEM} -lt 7900 ]; then
WITH_ROCKSDB=0
fi
cmake .. -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=${mysql_path} -DMYSQL_DATADIR=${mysql_path}/data -DSYSCONFDIR=${mysql_path}/conf -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 ${WITHOUT_TOKUDB} -DWITH_ROCKSDB=${WITH_ROCKSDB} -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci ${WITHOUT_ROUTER} ${WITHOUT_MYSQLX} -DWITH_RAPID=0 -DENABLED_LOCAL_INFILE=1 -DWITH_DEBUG=0 -DWITH_UNIT_TESTS=OFF -DINSTALL_MYSQLTESTDIR= -DCMAKE_BUILD_TYPE=Release -DWITH_SYSTEMD=1 -DSYSTEMD_PID_DIR=${mysql_path} ${WITH_BOOST}
if [ "$?" != "0" ]; then
error "编译初始化失败"
fi
make "-j${j}"
if [ "$?" != "0" ]; then
error "编译失败"
fi
# 停止已有服务
systemctl stop mysqld
# 安装
make install
if [ "$?" != "0" ]; then
error "安装失败"
fi
# 设置权限
chown -R mysql:mysql ${mysql_path}
chmod -R 700 ${mysql_path}
# 启动服务
systemctl daemon-reload
systemctl start mysqld
if [ "$?" != "0" ]; then
error "启动失败"
fi
# 执行更新后的初始化
if [[ "${channel}" == "percona_57" ]]; then
${mysql_path}/bin/mysql_upgrade -uroot -p${mysql_password}
fi
${mysql_path}/bin/mysql -uroot -p${mysql_password} -e "DROP DATABASE test;"
${mysql_path}/bin/mysql -uroot -p${mysql_password} -e "DELETE FROM mysql.user WHERE user='';"
${mysql_path}/bin/mysql -uroot -p${mysql_password} -e "FLUSH PRIVILEGES;"
panel-cli app write mysql ${channel} ${version}
echo -e $HR
echo "升级完成"
echo -e $HR