[数据库/Linux]CentOS7安装MySQL Percona版(RPM方式)
OS: CentOS7 (x86_64)
MySQL: MySQL Percona 5.7.31-34
0 前置条件
- 已配置完成YUM源
- 已卸载先前可能安装的MySQL
rpm -qa | grep -i mariadb
rpm -qa | grep -i mysql
rpm -qa | grep -i percona
rpm -e --nodeps xxxx.rpm
1 获得安装源
[方式1.1] 下载/上传/解压安装包
- Percona-Server-shared-57-5.7.31-34.1.el6.x86_64.rpm
- Percona-Server-server-57-5.7.31-34.1.el6.x86_64.rpm
- Percona-Server-client-57-5.7.31-34.1.el6.x86_64.rpm
- ...
(建议下载全包(bundle.tar),否则 容易出现各类依赖问题,较为费时费力)
假定:上传上述安装包(...-bundle.tar)至服务器 /opt/software/MySQL-Percona-57-Official-All/
[root@centos7-202010061038 ~]# cd /opt/software/MySQL-Percona-57-Official-All
[root@centos7-202010061038 ]# tar -xvf /opt/software/MySQL-Percona-57-Official-All/Percona-Server-5.7.31-34-r2e68637-el6-x86_64-bundle.tar
Percona-Server-57-debuginfo-5.7.31-34.1.el6.x86_64.rpm
Percona-Server-client-57-5.7.31-34.1.el6.x86_64.rpm
Percona-Server-devel-57-5.7.31-34.1.el6.x86_64.rpm
Percona-Server-rocksdb-57-5.7.31-34.1.el6.x86_64.rpm
Percona-Server-server-57-5.7.31-34.1.el6.x86_64.rpm
Percona-Server-shared-57-5.7.31-34.1.el6.x86_64.rpm
Percona-Server-test-57-5.7.31-34.1.el6.x86_64.rpm
Percona-Server-tokudb-57-5.7.31-34.1.el6.x86_64.rpm
[方式1.2] 配置 MySQL Percona的YUM源
rpm -Uvh https://www.percona.com/redir/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
更新过yum源后,会在 /etc/yum.repos.d/ 下生成 percona-release.repo,如下图:
先查看有哪些可用MySQL Percona的安装包
yum list | grep percona
yum list | grep Percona-Server-server
2 安装依赖组件
(采用[方式1.1/1.2]的均可略过,尤其是[方式1.2],方式1.1出依赖问题时,可再依次解决)
[下列命令 推荐 执行]
yum -y install libaio libaio-devel
[下列命令 可选 执行]
yum -y remove mariadb mariadb-libs python-cryptography python-pyasn1
yum -y install perl autoconf expect net-tools
yum -y install numactl numactl-devel
【解释1】依赖组件可避免的安装异常
[libaio]
安装此组件,可避免Percona-Server-server-*.rpm的依赖异常:
...
[ rpm -ivh Percona-Server-server-57*.rpm ] error: Failed dependencies:
libaio.so.1()(64bit) is needed by Percona-Server-server-57-5.7.24-27.1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by Percona-Server-server-57-5.7.24-27.1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by Percona-Server-server-57-5.7.24-27.1.el7.x86_64
...
[libsasl2.so.2]
安装此组件,可避免Percona-Server-server-*.rpm的依赖异常:
...
Loading mirror speeds from cached hostfile
* base: mirrors.sonic.net
* extras: mirror.lax.genesisadaptive.com
* updates: mirrors.ocf.berkeley.edu
---> Package Percona-Server-shared-57.x86_64 0:5.7.31-34.1.el6 will be installed
--> Finished Dependency Resolution
Error: Package: Percona-Server-server-57-5.7.31-34.1.el6.x86_64 (/Percona-Server-server-57-5.7.31-34.1.el6.x86_64)
Requires: libsasl2.so.2()(64bit)
You could try using --skip-broken to work around the problem
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
...
[libmysqlclient.so.18]
安装此组件,可避免Percona-Server-server-*.rpm的依赖异常:
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
Installing : Percona-Server-shared-57-5.7.31-34.1.el6.x86_64 1/2
Installing : Percona-Server-devel-57-5.7.31-34.1.el6.x86_64 2/2
Verifying : Percona-Server-shared-57-5.7.31-34.1.el6.x86_64 1/2
Verifying : Percona-Server-devel-57-5.7.31-34.1.el6.x86_64 2/2
Installed:
Percona-Server-devel-57.x86_64 0:5.7.31-34.1.el6 Percona-Server-shared-57.x86_64 0:5.7.31-34.1.el6
Skipped (dependency problems):
Percona-Server-client-57.x86_64 0:5.7.31-34.1.el6 Percona-Server-server-57.x86_64 0:5.7.31-34.1.el6
Complete!
2-1 依赖组件问题
可参见此文: [Linux]CentOS查看RPM包依赖问题 - 博客园/千千寰宇
【解释1】出现组件依赖问题时的解决办法/思路?
- 思路1: 【rpm方式】安装时去除依赖检查(
--nodeps
),并强制安装(--force
) | 【yum方式】跳过报错--skip-broken
或--nogpgcheck
(取消校验软件是否为官方发布)
rpm -ivh *.rpm --nodeps
yum localinstall --skip-broken ./*.rpm
yum (local)install --nogpgcheck Percona-Server-server-57-5.7.31-34.1.el6.x86_64.rpm
-
思路2: 根据报出的依赖异常,安装对应(版本)的依赖组件
(涉及问题:如何查询、下载、安装依赖组件?) -
思路3: 到其它服务器中拷贝同版本的依赖组件的安装包或文件
(拷贝文件的方法未实测,不保证可行性)
- 思路4:修改软链接/组件文件版本。
若服务器中已安装该依赖组件,但依赖组件版本(高于或)低于目标的组件版本,可使用此方式。
【解释2】如何查询/下载/安装依赖组件?
可参见此文: [Linux]CentOS查看RPM包依赖问题 - 博客园/千千寰宇
[root@centos7-202010061038 ~]# whereis libsasl2.so.2
libsasl2.so: /usr/lib64/libsasl2.so.3
[root@centos7-202010061038 ~]# ll /usr/lib64/libsasl2.so.3
lrwxrwxrwx. 1 root root 17 Aug 24 17:37 /usr/lib64/libsasl2.so.3 -> libsasl2.so.3.0.0
[root@centos7-202010061038 ~]# yum list installed | grep -i sasl
cyrus-sasl-lib.x86_64 2.1.26-23.el7 @CentOS
[root@centos7-202010061038 ~]# yum deplist cyrus-sasl-lib.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.sonic.net
* extras: mirror.lax.genesisadaptive.com
* updates: mirrors.ocf.berkeley.edu
package: cyrus-sasl-lib.x86_64 2.1.26-23.el7
dependency: /sbin/ldconfig
provider: glibc.x86_64 2.17-307.el7.1
provider: glibc.i686 2.17-307.el7.1
dependency: libc.so.6(GLIBC_2.15)(64bit)
provider: glibc.x86_64 2.17-307.el7.1
dependency: libcom_err.so.2()(64bit)
provider: libcom_err.x86_64 1.42.9-17.el7
dependency: libcrypt.so.1()(64bit)
provider: glibc.x86_64 2.17-307.el7.1
dependency: libdb-5.3.so()(64bit)
provider: libdb.x86_64 5.3.21-25.el7
dependency: libdl.so.2()(64bit)
provider: glibc.x86_64 2.17-307.el7.1
dependency: libdl.so.2(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-307.el7.1
dependency: libgssapi_krb5.so.2()(64bit)
provider: krb5-libs.x86_64 1.15.1-46.el7
dependency: libk5crypto.so.3()(64bit)
provider: krb5-libs.x86_64 1.15.1-46.el7
dependency: libkrb5.so.3()(64bit)
provider: krb5-libs.x86_64 1.15.1-46.el7
dependency: libkrb5support.so.0()(64bit)
provider: krb5-libs.x86_64 1.15.1-46.el7
dependency: libresolv.so.2()(64bit)
provider: glibc.x86_64 2.17-307.el7.1
dependency: rtld(GNU_HASH)
provider: glibc.x86_64 2.17-307.el7.1
provider: glibc.i686 2.17-307.el7.1
[root@centos7-202010061038 ~]# rpm -qR cyrus-sasl-lib
/sbin/ldconfig
/sbin/ldconfig
libanonymous.so.3()(64bit)
libc.so.6()(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.15)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
libcom_err.so.2()(64bit)
libcrypt.so.1()(64bit)
libdb-5.3.so()(64bit)
libdl.so.2()(64bit)
libdl.so.2(GLIBC_2.2.5)(64bit)
libgssapi_krb5.so.2()(64bit)
libk5crypto.so.3()(64bit)
libkrb5.so.3()(64bit)
libkrb5support.so.0()(64bit)
libresolv.so.2()(64bit)
libsasl2.so.3()(64bit)
libsasldb.so.3()(64bit)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1
可在下列Linux安装包资源网站中【查询/下载】是否存在对应版本的依赖组件包
- http://www.rpmfind.net/linux/rpm2html/search.php - rpmfind.net
- https://pkgs.org/search/?q= - pkgs.org
下载/安装 libsasl 的安装包(libsasl2-2.1.27-2.i686.rpm或cyrus-sasl-lib-2.1.23-15.el6_6.2.i686.rpm)
rpm -ivh xxx.rpm
3 安装数据库
[方式1.1]的安装命令
方式3.1.1 rpm -i
cd /opt/software/MySQL-Percona-57-Official-All
rpm -ivh *.rpm 或 rpm -ivh *.rpm --nodeps
rpm参数: i表示安装,U表示升级,v表示显示安装过程,h表示显示进度, --nodeps表示忽略依赖
方式3.1.2 yum localinstall
cd /opt/software/MySQL-Percona-57-Official-All
yum localinstall ./*.rpm
[方式1.2]的安装命令
yum install -y Percona-Server-shared-57.x86_64
yum install -y Percona-Server-devel-57.x86_64
yum install -y Percona-Server-client-57.x86_64
yum install -y Percona-Server-server-57.x86_64 或 yum install -y Percona-Server-server-57.x86_64 --nogpgcheck
4 初始化数据库
- step0 启动数据库,并配置开机启动
service mysql start 或 systemctl start mysql
service mysqld start 或 systemctl start mysqld
chkconfig --add mysql 或 systemctl enabled mysql
chkconfig --add mysqld 或 systemctl enabled mysqld
【注】mysql VS mysqld
mysql(客户端 / SQL命令行工具 / 交互式输入SQL语句或从文件以批处理模式执行它们的命令行工具)
mysqld(服务端 / mysql daemon / MySQL守护服务进程,常驻于后台)
【注】查看服务器中的开机自启服务
[centos7] systemctl list-unit-files | grep enabled
[centos6] chkconfig --list
- step1 获取数据库root用户初始密码
# cat /var/log/mysqld.log |grep "temporary password"
2020-10-12T09:29:04.877106Z 1 [Note] A temporary password is generated for root@localhost: e5vwDiI-;nOM
- step2 修改root用户密码
# pwd_str=123456
# root_passwd="'"$pwd_str"'"
# tmp_pwd_str=`cat /var/log/mysqld.log |grep "temporary password"`
# tmp_pwd=${tmp_pwd_str##*: }
# mysql -uroot -p${tmp_pwd} --connect-expired-password <<EOF
create user 'root'@'%' IDENTIFIED BY $root_passwd;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
EOF
- step3 设置
innodb_flush_log_at_trx_commit
[本步骤可忽略]
mysql -uroot -p$pwd_str -e "set global innodb_flush_log_at_trx_commit=0;"
mysql -uroot -p$pwd_str -e "set global innodb_flush_log_at_trx_commit=1;"
- END Over!
rpm -ivh Percona-Server-shared-57-*.rpm Percona-Server-server-57-*.rpm Percona-Server-client-57-*.rpm
X 推荐文献
本文链接: https://www.cnblogs.com/johnnyzen
关于博文:评论和私信会在第一时间回复,或直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
日常交流:大数据与软件开发-QQ交流群: 774386015 【入群二维码】参见左下角。您的支持、鼓励是博主技术写作的重要动力!