环境

  • CentOS 7.4 x86_64 最小安装
  • MySQL 5.7.20

下载 mysql 源安装包

```bash
# repo 地址: https://repo.mysql.com/
cd /root/
curl -O https://repo.mysql.com/mysql57-community-release-el7.rpm
```

安装 mysql 源

```bash
rpm -ivh /root/mysql57-community-release-el7.rpm
```

更新 yum 缓存

```bash
yum clean all
yum makecache fast
```

安装 mysql

```bash
yum install mysql-community-server
```

启动 mysql

```bash
systemctl start mysqld
```

查找 mysql 默认密码

```bash
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
# 输入查找到的密码
```

修改 mysql 本地密码

  • 在 mysql 下修改

    1
    
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Pass-1234';
    
  • 或者直接在终端修改

    1
    
    mysqladmin -uroot -p password 'Pass-1234'