安装mysql5.7

rpm包安装

步骤:

  1. 检查环境上是否已经有mysql: rpm -qa | grep mysql
  2. 准备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
  1. 安装时总时报错,查看文档知:阿里云默认安装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]# 
  1. 解压安装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:

  1. 下载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
  1. 使用yum安装:yum -y install mysql-community-server
  2. 若出现如下报错:
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
  1. 进入mysql:mysql -uroot -p,提示输入密码,密码在日志中可以搜索到。
我的密码搜索: journalctl -ru mysqld | grep password
指定了日志存放路径的密码搜索:grep "password" /var/log/mysqld.log
  1. 修改默认密码: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位;
  1. 删除mysql的yum源,避免自动更新:yum -y remove mysql57-community-release-el7-10.noarch
  2. 设置开机自启
systemctl enable mysqld
systemctl daemon-reload
  • yum安装mysql各个脚本的位置:“/usr/bin”

参考资料:

  1. https://blog.youkuaiyun.com/huaishu/article/details/78831737
  2. https://centos.pkgs.org/7/centos-x86_64/libaio-0.3.109-13.el7.x86_64.rpm.html
  3. https://www.cnblogs.com/jaychang/p/8652633.html
  4. https://www.bbsmax.com/A/x9J23kWK56/
  5. https://www.cnblogs.com/bigbrotherer/p/7241845.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值