yum安装mysql5.7(centos7)

前言:这里介绍使用yum工具安装mysql5.7。
一、更换yum源。(推荐阿里云)

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

在这里插入图片描述
添加epel源:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
在这里插入图片描述

查看mysql有没有安装过:
yum list installed | grep mysql
在这里插入图片描述

给centos添加rpm源:

centos7:
wget dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
centos7:
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
这里rmp源的版本可以自行下载最新的版本。现在mysql已经到8.0了。
centos7:
wget dev.mysql.com/get/mysql-community-release-el8.noarch.rpm

在这里插入图片描述
ls:
在这里插入图片描述
安装rpm源:

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

在这里插入图片描述
安装之后。
多出这mysql-community.repo和 mysql-community-source.repo两个文件。

[root@localhost yum.repos.d]# cat mysql-community.repo 
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

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

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

# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
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
这个就是yum安装所下载的对应的mysql的版本,其中每个版本对应下面的enabled很重要。0表示禁用,1表示可以下载。所以yum默认下载的就是enabled=1的,需要将其他的版本的enabled设置一下。

在这里插入图片描述
如下:
在这里插入图片描述
然后删除下载的rpm包:
在这里插入图片描述
yum clean all
yum makecache
yum -y update
在这里插入图片描述
重启操作系统然后下载mysql:
reboot

yum -y install mysql-community-server -------这样就默认下载mysql5.7的版本。
在这里插入图片描述

启动mysql:
systemctl start mysql
设置开机自启:
systemctl enable mysql
查看mysql的启动状态:
systemctl status mysql

由于mysql5.6以后版本的密码不是默认为空,所以密码在启动的日志文件。(如果实在不想去找那个默认的密码,直接跳过密码认证去修改密码也能实现。mysqld grant-skip-tables,然后修改密码。)
grep “password” /var/log/mysql.log
得到的结果就是密码:比如在这里用A表示。
在这里插入图片描述
然后登录mysql:

mysql -u root -p
复制粘贴密码:A
进入mysql的服务,然后修改密码。
alter user root@localhost identified by “新密码”;
在这里插入图片描述
在这里插入图片描述
总结:其实这样安装mysql依赖网络环境较大,所以可以考虑rpm包的安装方式,或者tar.gz的格式安装。源码安装的话还是很有挑战性的。
查看版本:
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值