这个脚本可以帮助您快速安装 Percona Server for MySQL。
您可以使用以下命令快速下载并执行安装脚本:
curl -fsSL https://raw.githubusercontent.com/xueba0458/Percona-Server-for-MySQL-installation-script/main/install.sh | bash
wget -qO- https://raw.githubusercontent.com/xueba0458/Percona-Server-for-MySQL-installation-script/main/install.sh | bash
- The official documentation does not provide the required dependencies. You need to wait for the compilation error to know which dependency is needed, which is very troublesome!
- It is convenient for me to quickly compile and install Percona Server for MySQL.
-
PVE, whether it is KVM virtualization or LXC containerized Debian and Ubuntu, cannot be compiled normally. I installed openldap, but cmake could not recognize it. I tried to manually compile and install openldap, and manually use parameters to force the specified library file, but it still doesn't work.... (I don't know how to program, I don't know how to solve it) ps: I don't know if I'm the only one with this problem, or if there is a problem with the official code!
-
The script was written by GPT4o, I haven't tested if it works properly! In theory it should work, if there are any problems, ask GPT4o!
- Install dependencies:
yum install git sudo gcc cmake make gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc openssl-devel openldap-devel cyrus-sasl-devel cyrus-sasl-scram krb5-devel ncurses-devel readline-devel bison libcurl-devel libudev-devel libtirpc-devel rpcgen libaio-devel libtirpc-devel
- Pull the Percona Server for MySQL source code:
cd /root
git config --global http.postBuffer 524288000
git clone https://github.com/percona/percona-server.git
cd percona-server
- Set the code branch:
git checkout 8.0
git submodule init
git submodule update
- A lot of files will be generated during the compilation process, create a folder to store them:
cmake ../percona-server -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_CONFIG=mysql_release -DFEATURE_SET=community
- Compile:
make -j4
ps: -j4 is configured according to the performance of your own server
- Install:
make install
- Create a user named mysql:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
- Create directory:
cd /usr/local/mysql
cd /usr/local/mysql && mkdir -p /usr/local/mysql/etc && mkdir -p mysql-files
- Set permissions:
chown mysql:mysql mysql-files && chmod 750 mysql-files
- Initialize the database:
cd /usr/local/mysql
./bin/mysqld --initialize-insecure --user=mysql
- Configure environment variables:
if ! grep -q "MYSQLPATH=/usr/local/mysql" /etc/profile; then
run_command "Configuring environment variables..." "echo 'export MYSQLPATH=/usr/local/mysql' >> /etc/profile && echo 'export PATH=\$MYSQLPATH/bin:\$MYSQLPATH/lib:\$PATH' >> /etc/profile && source /etc/profile"
else
echo "Environment variables have been configured, skip."
fi
- Create a configuration file, remember to modify the parameters yourself, otherwise don't blame me if there is a problem...
if [ ! -f "/usr/local/mysql/etc/my.cnf" ]; then
echo "Creating MySQL configuration file..."
cat <<EOF > /usr/local/mysql/etc/my.cnf
[mysqld]
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
#socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/usr/local/mysql/mysql-files
user=mysql
log_error_suppression_list='MY-013360'
character_set_server=utf8mb4
lower_case_table_names=1
group_concat_max_len=1024000
log_bin_trust_function_creators=1
#pid-file=/var/run/mysqld/mysqld.pid
key_buffer_size=512M
tmp_table_size=1024M
innodb_buffer_pool_size=1024M
sort_buffer_size=2M
read_buffer_size=2M
read_rnd_buffer_size=1024K
join_buffer_size=4M
thread_stack=384K
binlog_cache_size=192K
thread_cache_size=192
table_open_cache=1024
max_connections=400
[client]
#socket=/var/run/mysqld/mysqld.sock
EOF
else
echo "MySQL configuration file already exists, skip creation."
fi
- 官方文档没有提供需要的依赖,需要等编译报错之后才知道需要哪个依赖,很麻烦!
- 方便我自己快速编译安装 Percona Server for MySQL
-
PVE 无论是 KVM 虚拟化,还是 LXC 容器化的 Debian 和 Ubuntu 都没办法正常编译。 我安装了 openldap,但是 cmake 死活无法识别到,我试过手动编译安装 openldap,手动使用参数强制指定库文件,还是不行....(我不会编程,不知道咋解决) ps:我也不知道是不是只有我才有问题,还是官方的代码有问题!
-
脚本是 GPT4o 写的,我没有测试过能否正常使用!理论上可能也应该没有问题,有问题就问 GPT4o!
- 安装依赖:
yum install git sudo gcc cmake make gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc openssl-devel openldap-devel cyrus-sasl-devel cyrus-sasl-scram krb5-devel ncurses-devel readline-devel bison libcurl-devel libudev-devel libtirpc-devel rpcgen libaio-devel libtirpc-devel
- 拉取 Percona Server for MySQL 源代码:
cd /root
git config --global http.postBuffer 524288000
git clone https://github.com/percona/percona-server.git
cd percona-server
- 设置代码分支:
git checkout 8.0
git submodule init
git submodule update
- 编译过程中会生成很多文件,创建一个文件夹用来存放:
cmake ../percona-server -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_CONFIG=mysql_release -DFEATURE_SET=community
- 编译:
make -j4
ps: -j4 按自己的服务器性能配置
- 安装:
make install
- 创建一个叫 mysql 的用户:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
- 创建目录:
cd /usr/local/mysql
cd /usr/local/mysql && mkdir -p /usr/local/mysql/etc && mkdir -p mysql-files
- 设置权限:
chown mysql:mysql mysql-files && chmod 750 mysql-files
- 初始化数据库:
cd /usr/local/mysql
./bin/mysqld --initialize-insecure --user=mysql
- 配置环境变量:
if ! grep -q "MYSQLPATH=/usr/local/mysql" /etc/profile; then
run_command "配置环境变量..." "echo 'export MYSQLPATH=/usr/local/mysql' >> /etc/profile && echo 'export PATH=\$MYSQLPATH/bin:\$MYSQLPATH/lib:\$PATH' >> /etc/profile && source /etc/profile"
else
echo "环境变量已配置,跳过。"
fi
- 创建配置文件,记得自己修改参数,不然出了问题别怪我...
if [ ! -f "/usr/local/mysql/etc/my.cnf" ]; then
echo "创建 MySQL 配置文件..."
cat <<EOF > /usr/local/mysql/etc/my.cnf
[mysqld]
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
#socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/usr/local/mysql/mysql-files
user=mysql
log_error_suppression_list='MY-013360'
character_set_server=utf8mb4
lower_case_table_names=1
group_concat_max_len=1024000
log_bin_trust_function_creators=1
#pid-file=/var/run/mysqld/mysqld.pid
key_buffer_size=512M
tmp_table_size=1024M
innodb_buffer_pool_size=1024M
sort_buffer_size=2M
read_buffer_size=2M
read_rnd_buffer_size=1024K
join_buffer_size=4M
thread_stack=384K
binlog_cache_size=192K
thread_cache_size=192
table_open_cache=1024
max_connections=400
[client]
#socket=/var/run/mysqld/mysqld.sock
EOF
else
echo "MySQL 配置文件已存在,跳过创建。"
fi