前言:这里介绍使用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的格式安装。源码安装的话还是很有挑战性的。
查看版本: