download/panel/mysql/install.sh
耗子 296eb1ef45
Some checks failed
Generate Checksums / checksums (push) Has been cancelled
feat: 修复code-server安装
2025-04-13 18:00:27 +08:00

429 lines
20 KiB (Stored with Git LFS)
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
: '
Copyright (C) 2022 - now HaoZi Technology Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'
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"
j=$(calculate_j)
# 安装依赖
if [ ${OS} == "rhel" ]; then
dnf makecache -y
dnf groupinstall "Development Tools" -y
dnf install cmake bison ncurses-devel libtirpc-devel openssl-devel pkg-config systemd-devel openldap-devel libudev-devel cyrus-sasl-devel cyrus-sasl-scram patchelf rpcgen rpcsvc-proto-devel krb5-devel zlib-devel readline-devel libcurl-devel -y
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get update
apt-get install build-essential cmake bison libncurses5-dev libtirpc-dev libssl-dev pkg-config libsystemd-dev libldap2-dev libudev-dev libsasl2-dev libsasl2-modules-gssapi-mit patchelf libkrb5-dev zlib1g-dev libreadline-dev libcurl4-openssl-dev -y
else
error "不支持的操作系统"
fi
if [ "$?" != "0" ]; then
error "安装依赖软件失败"
fi
mysql_user_check=$(cat /etc/passwd | grep mysql)
if [ "${mysql_user_check}" == "" ]; then
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
fi
# 准备目录
rm -rf ${mysql_path}
mkdir -p ${mysql_path}
cd ${mysql_path}
# 下载源码
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 -rf ${mysql_path}
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
rm -rf ${mysql_path}
error "编译初始化失败"
fi
make "-j${j}"
if [ "$?" != "0" ]; then
rm -rf ${mysql_path}
error "编译失败"
fi
# 安装
make install
if [ "$?" != "0" ]; then
rm -rf ${mysql_path}
error "安装失败"
fi
# 配置
mkdir ${mysql_path}/conf
cat >${mysql_path}/conf/my.cnf <<EOF
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = ${mysql_path}/data
default_storage_engine = InnoDB
skip-external-locking
table_definition_cache = 400
performance_schema = off
event_scheduler = off
key_buffer_size = 8M
max_allowed_packet = 1G
table_open_cache = 32
sort_buffer_size = 256K
read_buffer_size = 256K
join_buffer_size = 256K
read_rnd_buffer_size = 256K
thread_stack = 256K
net_buffer_length = 4K
myisam_sort_buffer_size = 4M
thread_cache_size = 4
query_cache_size = 4M
tmp_table_size = 8M
explicit_defaults_for_timestamp = 1
#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
early-plugin-load = ""
log-bin = mysql-bin
server-id = 1
slow_query_log = 1
slow-query-log-file = ${mysql_path}/mysql-slow.log
long_query_time = 3
innodb_data_home_dir = ${mysql_path}/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = ${mysql_path}/data
innodb_buffer_pool_size = 16M
innodb_redo_log_capacity = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
[mysqldump]
quick
max_allowed_packet = 2G
[mysqlhotcopy]
interactive-timeout
EOF
# 根据CPU核心数确定写入线程数核心数的一半
half_cores=$((CORES / 2))
[ "$half_cores" -lt 1 ] && half_cores=1
sed -i 's/innodb_write_io_threads = 4/innodb_write_io_threads = '${half_cores}'/g' ${mysql_path}/conf/my.cnf
sed -i 's/innodb_read_io_threads = 4/innodb_read_io_threads = '${half_cores}'/g' ${mysql_path}/conf/my.cnf
# MySQL 8+ 移除 query_cache
if [[ ${channel} == "percona_80" ]] || [[ ${channel} == "percona_84" ]]; then
sed -i '/query_cache_size/d' ${mysql_path}/conf/my.cnf
fi
# MySQL 5.7 没有 innodb_redo_log_capacity
if [[ ${channel} == "percona_57" ]]; then
sed -i '/innodb_redo_log_capacity/d' ${mysql_path}/conf/my.cnf
fi
# 根据内存大小调参
if [[ ${MEM} -lt 1500 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 16#" ${mysql_path}/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 64K#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 64K#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_rnd_buffer_size.*#read_rnd_buffer_size = 128K#" ${mysql_path}/conf/my.cnf
sed -i "s#^join_buffer_size.*#join_buffer_size = 128K#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_stack.*#thread_stack = 192K#" ${mysql_path}/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 0#" ${mysql_path}/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 0#" ${mysql_path}/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 5M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_redo_log_capacity.*#innodb_redo_log_capacity = 8M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_log_buffer_size.*#innodb_log_buffer_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^max_connections.*#max_connections = 30#" ${mysql_path}/conf/my.cnf
elif [[ ${MEM} -ge 1500 && ${MEM} -lt 1900 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 8M#" ${mysql_path}/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 64#" ${mysql_path}/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 256K#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 256K#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_rnd_buffer_size.*#read_rnd_buffer_size = 256K#" ${mysql_path}/conf/my.cnf
sed -i "s#^join_buffer_size.*#join_buffer_size = 128K#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_stack.*#thread_stack = 192K#" ${mysql_path}/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 8M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 16#" ${mysql_path}/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 16M#" ${mysql_path}/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 16M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 64M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_redo_log_capacity.*#innodb_redo_log_capacity = 64M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_log_buffer_size.*#innodb_log_buffer_size = 16M#" ${mysql_path}/conf/my.cnf
sed -i "s#^max_connections.*#max_connections = 50#" ${mysql_path}/conf/my.cnf
elif [[ ${MEM} -ge 1900 && ${MEM} -lt 3900 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 16M#" ${mysql_path}/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 256#" ${mysql_path}/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 512K#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 512K#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_rnd_buffer_size.*#read_rnd_buffer_size = 512K#" ${mysql_path}/conf/my.cnf
sed -i "s#^join_buffer_size.*#join_buffer_size = 256K#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_stack.*#thread_stack = 256K#" ${mysql_path}/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 16M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 32#" ${mysql_path}/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 32M#" ${mysql_path}/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 32M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 128M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_redo_log_capacity.*#innodb_redo_log_capacity = 128M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_log_buffer_size.*#innodb_log_buffer_size = 32M#" ${mysql_path}/conf/my.cnf
sed -i "s#^max_connections.*#max_connections = 100#" ${mysql_path}/conf/my.cnf
elif [[ ${MEM} -ge 3900 && ${MEM} -lt 7900 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 32M#" ${mysql_path}/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 512#" ${mysql_path}/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_rnd_buffer_size.*#read_rnd_buffer_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^join_buffer_size.*#join_buffer_size = 512K#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_stack.*#thread_stack = 256K#" ${mysql_path}/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 32M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 64#" ${mysql_path}/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 64M#" ${mysql_path}/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 64M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 256M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_redo_log_capacity.*#innodb_redo_log_capacity = 256M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_log_buffer_size.*#innodb_log_buffer_size = 64M#" ${mysql_path}/conf/my.cnf
sed -i "s#^max_connections.*#max_connections = 200#" ${mysql_path}/conf/my.cnf
elif [[ ${MEM} -ge 7900 && ${MEM} -lt 15900 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 64M#" ${mysql_path}/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 1024#" ${mysql_path}/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 2M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 2M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_rnd_buffer_size.*#read_rnd_buffer_size = 2M#" ${mysql_path}/conf/my.cnf
sed -i "s#^join_buffer_size.*#join_buffer_size = 1M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_stack.*#thread_stack = 384K#" ${mysql_path}/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 64M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 128#" ${mysql_path}/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 128M#" ${mysql_path}/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 128M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 512M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_redo_log_capacity.*#innodb_redo_log_capacity = 512M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_log_buffer_size.*#innodb_log_buffer_size = 128M#" ${mysql_path}/conf/my.cnf
sed -i "s#^max_connections.*#max_connections = 300#" ${mysql_path}/conf/my.cnf
elif [[ ${MEM} -ge 15900 && ${MEM} -lt 31900 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 128M#" ${mysql_path}/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 2048#" ${mysql_path}/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 4M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 4M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_rnd_buffer_size.*#read_rnd_buffer_size = 4M#" ${mysql_path}/conf/my.cnf
sed -i "s#^join_buffer_size.*#join_buffer_size = 2M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_stack.*#thread_stack = 512K#" ${mysql_path}/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 128M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 256#" ${mysql_path}/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 256M#" ${mysql_path}/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 256M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 1G#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_redo_log_capacity.*#innodb_redo_log_capacity = 1G#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_log_buffer_size.*#innodb_log_buffer_size = 256M#" ${mysql_path}/conf/my.cnf
sed -i "s#^max_connections.*#max_connections = 400#" ${mysql_path}/conf/my.cnf
sed -i '/performance_schema/d' ${mysql_path}/conf/my.cnf
sed -i '/event_scheduler/d' ${mysql_path}/conf/my.cnf
elif [[ ${MEM} -ge 31900 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 256M#" ${mysql_path}/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 4096#" ${mysql_path}/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 8M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 8M#" ${mysql_path}/conf/my.cnf
sed -i "s#^read_rnd_buffer_size.*#read_rnd_buffer_size = 8M#" ${mysql_path}/conf/my.cnf
sed -i "s#^join_buffer_size.*#join_buffer_size = 4M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_stack.*#thread_stack = 512K#" ${mysql_path}/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 256M#" ${mysql_path}/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 512#" ${mysql_path}/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 512M#" ${mysql_path}/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 512M#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 2G#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_redo_log_capacity.*#innodb_redo_log_capacity = 2G#" ${mysql_path}/conf/my.cnf
sed -i "s#^innodb_log_buffer_size.*#innodb_log_buffer_size = 512M#" ${mysql_path}/conf/my.cnf
sed -i '/performance_schema/d' ${mysql_path}/conf/my.cnf
sed -i '/event_scheduler/d' ${mysql_path}/conf/my.cnf
fi
# 初始化
cd ${mysql_path}
rm -rf ${mysql_path}/src
rm -rf ${mysql_path}/data
mkdir -p ${mysql_path}/data
chown -R mysql:mysql ${mysql_path}
chmod -R 700 ${mysql_path}
${mysql_path}/bin/mysqld --initialize-insecure --user=mysql --basedir=${mysql_path} --datadir=${mysql_path}/data
# 软链接
ln -sf ${mysql_path}/bin/* /usr/bin/
# 写入 systemd 配置
cat >/etc/systemd/system/mysqld.service <<EOF
[Unit]
Description=MySQL Server
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network-online.target
Wants=network-online.target
After=syslog.target
After=local-fs.target remote-fs.target
Requires=local-fs.target remote-fs.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=${mysql_path}/mysqld.pid
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Start main service
ExecStart=${mysql_path}/bin/mysqld --daemonize --pid-file=${mysql_path}/mysqld.pid \$MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 500000
Restart=on-failure
RestartPreventExitStatus=1
# Set enviroment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
EOF
chmod 644 /etc/systemd/system/mysqld.service
systemctl daemon-reload
systemctl enable --now mysqld
if [ "$?" != "0" ]; then
error "启动失败"
fi
# 等待 MySQL 启动
for i in {1..60}; do
if mysqladmin ping &>/dev/null; then
echo "MySQL 服务已启动"
break
fi
echo "等待 MySQL 启动..."
sleep 1
done
if ! mysqladmin ping &>/dev/null; then
error "MySQL 启动超时"
fi
root_password=$(cat /dev/urandom | head -n 16 | sha256sum | head -c 16)
${mysql_path}/bin/mysqladmin -u root password ${root_password}
if [ "$?" != "0" ]; then
error "初始化密码失败"
fi
${mysql_path}/bin/mysql -uroot -p${root_password} -e "DROP DATABASE test;"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "DELETE FROM mysql.user WHERE user='';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "FLUSH PRIVILEGES;"
# 启用 RocksDB
if [ ${WITH_ROCKSDB} -eq 1 ]; then
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_CFSTATS SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_DBSTATS SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_PERF_CONTEXT SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_PERF_CONTEXT_GLOBAL SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_CF_OPTIONS SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_GLOBAL_INFO SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_COMPACTION_HISTORY SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_COMPACTION_STATS SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_ACTIVE_COMPACTION_STATS SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_DDL SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_INDEX_FILE_MAP SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_LOCKS SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_TRX SONAME 'ha_rocksdb.so';"
${mysql_path}/bin/mysql -uroot -p${root_password} -e "INSTALL PLUGIN ROCKSDB_DEADLOCK SONAME 'ha_rocksdb.so';"
fi
panel-cli app write mysql ${channel} ${version}
panel-cli setting write mysql_root_password ${root_password}
panel-cli database add-server --type=mysql --name=local_mysql --host=127.0.0.1 --port=3306 --username=root --password=${root_password}
echo -e $HR
echo "安装完成"
echo -e $HR