一、下载安装rpm
- 进入官方网址点击 MySQL Community Edition DOWNLOAD
- Download MySQL Yum Repository(通过yum安装)
- 找到对应的Linux系统下载yum
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
二、安装mysql yum源
1、安装mysql yum
yum localinstall /opt/mysql80-community-release-el7-1.noarch.rpm
2、修改要安装的版本
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
3、检查一下现在的mysql yum配置
[root@iZbp1fkgp9zwe32kb9wft6Z yum.repos.d]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 63
mysql-tools-community/x86_64 MySQL Tools Community 69
mysql57-community/x86_64 MySQL 5.7 Community Server 287
三、安装mysql
[root@iZbp1fkgp9zwe32kb9wft6Z yum.repos.d]# yum install mysql-community-server
......
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.23-1.el7 mysql57-community 2.2 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-libs-compat x86_64 5.7.23-1.el7 mysql57-community 2.0 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.7.23-1.el7 mysql57-community 165 M
Installing for dependencies:
libaio x86_64 0.3.109-13.el7 base 24 k
mysql-community-client x86_64 5.7.23-1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.23-1.el7 mysql57-community 274 k
Transaction Summary
==========================================================================================================================================================
Install 3 Packages (+3 Dependent packages)
Total download size: 194 M
Is this ok [y/d/N]: y
四、启动服务
1、启动服务
2、查看root用户密码
3、登陆,输入密码
[root@iZbp1fkgp9zwe32kb9wft6Z yum.repos.d]# systemctl start mysqld
[root@iZbp1fkgp9zwe32kb9wft6Z yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2018-08-13T01:19:05.655823Z 1 [Note] A temporary password is generated for root@localhost: exgl3Iffg>qk
[root@iZbp1fkgp9zwe32kb9wft6Z yum.repos.d]# mysql -uroot -p
Enter password:
五、修改默认密码
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'Pass%word1_';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)