记录该文档的初衷是记录一下安装记录,因为以前总是安装的时候导出查,而且经常碰到这样那样的坑。所以打算从头开始重新安装一遍,整片文档基于MySQL官网
一、基于Yum安装MySQL8
1、添加Yum存储库
文档地址:
官网原文:
First, add the MySQL Yum repository to your system’s repository list. This is a one-time operation, which can be performed by installing an RPM provided by MySQL. Follow these steps:
- Go to the Download MySQL Yum Repository page (https://dev.mysql.com/downloads/repo/yum/) in the MySQL Developer Zone.
- Select and download the release package for your platform.
- Install the downloaded release package with the following command, replacing platform-and-version-specific-package-name with the name of the downloaded RPM package:
翻译过来:
1、首先,将MySQL Yum存储库添加到系统的存储库列表中。此操作为一次性操作,只需安装MySQL提供的RPM即可完成。遵循以下步骤:
a、去对应的Yum仓库下载对应的对应的资源地址为:https://dev.mysql.com/downloads/repo/yum/
(当然这里也可以直接从服务器上下载)
b、选择适合我们平台的发布包(这里我们以centos7为例)
c、使用如下命令安装,将platform-and-version-specific-package-name替换为下载的RPM包名称:
补充:在安装前最好删除系统自带的MariaDB
查询是否安装了MariaDB: rpm -qa | grep mariadb
删除命令:rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
删除完成后再次查询:rpm -qa | grep mariadb
2、将下载好的rpm文件上传至服务器(本文以 /usr/local/soft)
3、安装 yum install mysql80-community-release-el7-6.noarch.rpm
4、更新yum库
yum makecache
2、安装MySQL
1、yum install mysql-community-server
(这里有个坑!!!)
2、检查rpm文件前面是否正确
rpm --checksig mysql80-community-release-el7-6.noarch.rpm
可以发现没有秘钥,那么我们导入秘钥
3、导入秘钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
导入成功后再次检查秘钥
rpm --checksig mysql80-community-release-el7-6.noarch.rpm
4、安装MySQL
yum install mysql-community-server
5、启动MySQL,并设置为开机启
启动Mysql:systemctl start mysqld
开机自启动:systemctl enable mysqld
3、配置Mysql
在完成了MySQL的安装之后我们需要进行一定的配置才能使用。首先就是要修改密码
1、修改密码
mysql默认的日志文件位于 /var/log/mysqld.log
cat /var/log/mysqld.log
2、登陆MySQL并修改密码
mysql -uroot -p
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY 密码;
至此Mysql的安装已经完成,如果在使用过程中发现客户端无法连接到mysql可能是防火墙的原因。希望对有所帮助
参考:
https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html