环境

  • CentOS 7.4 x86_64 最小安装
  • MySQL 5.7.20

下载 mysql 源安装包

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

安装 mysql 源

1
rpm -ivh /root/mysql57-community-release-el7.rpm

更新 yum 缓存

1
2
yum clean all
yum makecache fast

安装 mysql

1
yum install mysql-community-server

启动 mysql

1
systemctl start mysqld

查找 mysql 默认密码

1
2
3
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'