1. #!/usr/bin/bash
    2. set -e
    3. rpm -e --nodeps mariadb-libs
    4. yum install -y libaio numactl
    5. wget "https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz" -O mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
    6. tar -Jxvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
    7. mv mysql-8.0.21-linux-glibc2.12-x86_64/ /usr/local/mysql/
    8. groupadd mysql
    9. useradd -r -g mysql -s /bin/false mysql
    10. chown -R mysql:mysql /usr/local/mysql
    11. cd /usr/local/mysql/
    12. if [ -f "/etc/my.cnf" ]; then
    13. mv /etc/my.cnf /etc/my.cnf.bak
    14. fi
    15. /usr/local/mysql/bin/mysqld --initialize --user=mysql |& tee init.log
    16. cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
    17. systemctl daemon-reload
    18. systemctl start mysql
    19. sqlpasswd=$(cat /usr/local/mysql/init.log | sed -n '$p' | egrep -o localhost.* | awk -F 'host: ' '{print $2}')
    20. bin/mysql --connect-expired-password -u root -p$sqlpasswd <<- 'EOF'
    21. ALTER USER 'root'@'localhost' IDENTIFIED WITH CACHING_SHA2_PASSWORD BY 'password';
    22. FLUSH PRIVILEGES;
    23. EOF
    24. echo -e "Your root password is \"password\""
    25. echo -e "MySQL has successfully installed"