3.3.2 centos7建立mysql服务——安装mysql

2. 安装mysql

2.1 获取mysql安装yum源,并安装

[[email protected] ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[[email protected] ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

添加Mysql yum源

[[email protected] ~]# vi /etc/yum.repos.d/mysql-community.repo

在mysql-community.repo中添加如下内容

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 8.0
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

按下ESC,输入:wq,保存并退出

查看mysql-community.repo

[[email protected] ~]# cat /etc/yum.repos.d/mysql-community.repo

看到如下图, 表示添加成功
3.3.2 centos7建立mysql服务——安装mysql
查看mysql的子存储库,并安装(这里我修改为8.0的MySQL,所以查询到的是8.0的子存储库)

[[email protected] ~]# yum repolist enabled | grep mysql
!mysql80-community/x86_64 MySQL 8.0 Community Server                         82

通过运行以下命令更新yum 源来更新MySQL

[[email protected] ~]# yum update
[[email protected] ~]# yum install mysql-community-server

查看mysql启用状态和文件位置

ps aux | grep mysql