#!/usr/bin/env bash
# filename: mysql57_install.sh

cat > /etc/yum.repos.d/MySQL57.repo<<EOF
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY

EOF

yum install mysql-community-server -y

systemctl enable mysqld --now

temp_pwd=$(grep 'temporary password' /var/log/mysqld.log | awk -F: '{print $4}')

echo root password: $temp_pwd
