rpm包安装
步骤:
- 检查环境上是否已经有mysql:
rpm -qa | grep mysql
- 准备rpm包:
操作系统: “CentOS Linux release 7.2.1511 (Core)”
mysql-community-common-5.7.25-1.el6.x86_64.rpm
mysql-community-libs-5.7.25-1.el6.x86_64.rpm
mysql-community-server-5.7.25-1.el6.x86_64.rpm
mysql-community-client-5.7.25-1.el6.x86_64.rpm
- 安装时总时报错,查看文档知:
阿里云默认安装mariadb-lib,先卸载mariadb,再安装mysql
,故有如下操作:
[root@localhost mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@localhost mysql]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps
[root@localhost mysql]# rpm -qa|grep mariadb
[root@localhost mysql]#
- 解压安装rpm包:
[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm
警告:mysql-community-common-5.7.25-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.25-1.e################################# [100%]
[root@localhost mysql]# rpm -qa | grep mysql
mysql-community-common-5.7.25-1.el6.x86_64
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.25-1.el6.x86_64.rpm
警告:mysql-community-libs-5.7.25-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.25-1.el6################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.25-1.el6.x86_64.rpm
警告:mysql-community-server-5.7.25-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
libaio.so.1()(64bit) 被 mysql-community-server-5.7.25-1.el6.x86_64 需要
libaio.so.1(LIBAIO_0.1)(64bit) 被 mysql-community-server-5.7.25-1.el6.x86_64 需要
libaio.so.1(LIBAIO_0.4)(64bit) 被 mysql-community-server-5.7.25-1.el6.x86_64 需要
libsasl2.so.2()(64bit) 被 mysql-community-server-5.7.25-1.el6.x86_64 需要
mysql-community-client(x86-64) >= 5.7.9 被 mysql-community-server-5.7.25-1.el6.x86_64 需要
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.25-1.el6.x86_64.rpm
警告:mysql-community-client-5.7.25-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.25-1.e################################# [100%]
[root@localhost mysql]#
可以看到安装server失败,首先缺少库:
libaio-0.3.109-13.el7.x86_64.rpm-----libaio.so.1
安装:
wget mirror.centos.org/centos/7/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm
[root@localhost mysql]# rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:libaio-0.3.109-13.el7 ################################# [100%]
最终结果:安装失败 原因:在centos7上装centos6的安装包,缺少系统库libsasl2.so.2.需下载对应版本的rpm包
yum安装mysql7:
- 下载mysql源:
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 使用yum安装:
yum -y install mysql-community-server
- 若出现如下报错:
The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed
but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
-----
The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
这是由于MySQL GPG 密钥已过期导致的 问题解决出处
需要运行命令, 以2022年为例
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
重新执行安装命令: yum -y install mysql-community-server
4. 修改配置为自己需要的;
5. 启动:systemctl start mysqld.service
6. 查看启动状态:systemctl status mysqld.service
- 由于使用了自己的配置文件,指定了数据文件路径,且没有指定日志路径;造成数据库启动失败,且没有日志,日志被系统管理,查看方法:
journalctl -ru mysqld
- 进入mysql:
mysql -uroot -p
,提示输入密码,密码在日志中可以搜索到。
我的密码搜索: journalctl -ru mysqld | grep password
指定了日志存放路径的密码搜索:grep "password" /var/log/mysqld.log
- 修改默认密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
- 由于密码存在密码规则,故需要修改密码规则后才可以设置简单的密码,修改方式:
SHOW VARIABLES LIKE 'validate_password%'; #查看密码规则
set global validate_password_policy=0; #0表示仅校验长度;
set global validate_password_length=1; #密码长度最短允许为1位;
- 删除mysql的yum源,避免自动更新:
yum -y remove mysql57-community-release-el7-10.noarch
- 设置开机自启
systemctl enable mysqld
systemctl daemon-reload
- yum安装mysql各个脚本的位置:“/usr/bin”
参考资料:
- https://blog.youkuaiyun.com/huaishu/article/details/78831737
- https://centos.pkgs.org/7/centos-x86_64/libaio-0.3.109-13.el7.x86_64.rpm.html
- https://www.cnblogs.com/jaychang/p/8652633.html
- https://www.bbsmax.com/A/x9J23kWK56/
- https://www.cnblogs.com/bigbrotherer/p/7241845.html