官网地址 https://dev.mysql.com/downloads/repo/yum/

    1. wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
    2. yum localinstall mysql80-community-release-el7-3.noarch.rpm
    3. yum repolist enabled | grep "mysql.*-community.*"

    选择指定版本。

    1. vim /etc/yum.repos.d/mysql-community.repo

    把5.7的enabled设置成1并且把8.0的设置成0

    1. # Enable to use MySQL 5.7
    2. [mysql57-community]
    3. name=MySQL 5.7 Community Server
    4. baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
    5. enabled=1
    6. gpgcheck=1
    7. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    8. [mysql80-community]
    9. name=MySQL 8.0 Community Server
    10. baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
    11. enabled=0
    12. gpgcheck=1
    13. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    1. yum install -y mysql-community-server
    2. # 启动MySQL
    3. systemctl start mysqld
    4. systemctl status mysqld
    5. # 设置开启重启
    6. systemctl enable mysqld
    7. systemctl daemon-reload

    初次安装 root密码位置

    1. grep 'temporary password' /var/log/mysqld.log
    2. shell> mysql -uroot -p
    3. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
    4. 或者
    5. mysql> set password for 'root'@'localhost'=password('root');

    如果不能设置简单密码,开发环境可以调整如下参数

    1. mysql> set global validate_password_policy=0;
    2. # 5.7密码长度不能小于4
    3. mysql> set global validate_password_length=4;