1 检查是否安装过
MySQL
rpm -qa | grep -i mysql
mariadb
rpm -qa | grep mariadb
2 卸载之前的安装
MySQL
rpm -e --nodeps 软件名 //强力删除,对相关依赖的文件也进行强力删除
卸载
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
3 官网下载
MySQL :: Download MySQL Community Server
mysql-community-client-8.0.32-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.32-1.el7.x86_64.rpm
mysql-community-common-8.0.32-1.el7.x86_64.rpm
mysql-community-libs-8.0.32-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.32-1.el7.x86_64.rpm
mysql-community-server-8.0.32-1.el7.x86_64.rpm
4 安装客户端(mysql-client)
rpm -ivh rpm包
4.1 安装mysql-community-common-8.0.32
rpm -ivh mysql-community-common-8.0.32-1.el7.x86_64.rpm
4.2 安装mysql-community-client-plugins-8.0.32
rpm -ivh mysql-community-libs-8.0.32-1.el7.x86_64.rpm --force --nodeps
4.3 安装mysql-community-libs-8.0.32
rpm -ivh mysql-community-client-plugins-8.0.32-1.el7.x86_64.rpm
4.4 安装mysql-community-client-8.0.32(前面是其依赖)
rpm -ivh mysql-community-client-8.0.32-1.el7.x86_64.rpm
4.5 安装mysql-community-icu-data-files-8.0.32
rpm -ivh mysql-community-icu-data-files-8.0.32-1.el7.x86_64.rpm
4.6 安装 mysql-community-icu-data-files-8.0.32
rpm -ivh mysql-community-icu-data-files-8.0.32-1.el7.x86_64.rpm
5 安装服务端(mysql-server)
rpm -ivh mysql-community-server-8.0.32-1.el7.x86_64.rpm
6 查看是否安装成功
有以下方式查看:
-
ps -ef | grep mysql
-
cat /etc/group | grep mysql
-
cat /etc/password | grep mysql
-
mysqladmin --version
7 初始化mysql
初始化之前可以修改 /etc/my.cnf 文件配置文件路径
mysqld --initialize //创建数据文件目录和mysql系统数据库 产生随机root密码
8 /var/lib/mysql目录权限授权
chown -R mysql:mysql /var/lib/mysql/
9 启动mysql服务
systemctl start mysqld
ps -ef | grep mysql //查看mysql服务
10 查看初始化随机生成的root密码
cat /var/log/mysqld.log | grep password
11 安全设置
mysql_secure_installation
12 重置密码(Mysql8.0+有变化)
先把root的旧密码置空
use mysql;
update user set authentication_string='' where user='root';
备注:Mysql5.7+ password字段 已改成 authentication_string字段
重置成新密码
alter user 'root'@'localhost' identified by 'newpassword';
备注:Mysql8.0修改密码方式已有变化(此处是个坑,需要注意)
Mysql8.0之前:
update user set password=password('root') where user='root';
13 允许远程连接
use mysql;
update user set host = '%' where user = 'root';
flush privileges;
参考:
- mysql8 rpm安装_CentOS8 安装 MySQL8.0(RPM)