Centos7下yum安装mysql5.7

文章目录

    • 安装环境
    • 安装过程

安装环境

CentOS-7

安装过程

(1)更换yum源

打开阿里云官方镜像,选择合适的CentOS版本,https://developer.aliyun.com/mirror/

Note:这里一定要先看一下自己的CentOS版本,使用对应的yum源,阿里的这个文档写的还是很好的。

备份之前的yum源仓库

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

(2)下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

(3)更新本地缓存

yum clean all
yum makecache

(4)查看系统中是否自带mysql

yum list installed | grep mysql

(5)删除自带的mysql库

yum -y remove mysql-libs.x86_64

(6)下载mysql-community对应的rpm包

# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

(7)安装下载好的rpm包

# yum install mysql-community-release-el7-5.noarch.rpm -y

(8)安装好后,在/etc/yum.repo.d/文件夹下会增加2个文件

# ls
CentOS-Base.repo         CentOS-Debuginfo.repo  CentOS-Sources.repo        mysql-community.repo
CentOS-Base.repo.backup  CentOS-fasttrack.repo  CentOS-Vault.repo          mysql-community-source.repo
CentOS-CR.repo           CentOS-Media.repo      CentOS-x86_64-kernel.repo

mysql-community.repo和mysql-community-source.repo,修改mysql-community.repo。将mysql5.7的enable设置为1。

Centos7下yum安装mysql5.7_第1张图片

(9)yum install 安装mysql

# yum install mysql-community-server -y

(10)启动mysql并设置开机自启

#启动之前需要生成临时密码,需要用到证书,可能证书过期,需要进行更新操作
# yum update -y
#启动mysql服务
service mysqld start
#设置mysql开机启动
chkconfig mysqld on

(11)获取临时密码

# grep "password" /var/log/mysqld.log 
2020-08-14T08:46:01.553820Z 1 [Note] A temporary password is generated for root@localhost: bt7Np(rl:C##

(12)修改密码

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

(13)设置远程访问权限

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

参考:https://zhuanlan.zhihu.com/p/95871536

你可能感兴趣的:(mysql)