jiaoben.txt/install-myaql.sh

26 lines
841 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/bash
# 准备MySQL的yum仓库
yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
# 修改安装版本启用5.7版本
yum -y install yum-utils
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
# 安装MySQL服务器和客户端
yum -y install mysql mysql-server mysql-community-client mysql-community-server
# 初始化MySQL服务
systemctl start mysqld
systemctl enable mysqld
# 获取MySQL生成的临时密码
MYSQL_ROOT_PASSWORD=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}')
# 提示用户输入新的密码
echo "请输入新的MySQL root用户密码:"
read -s NEW_MYSQL_ROOT_PASSWORD
echo
# 使用mysql客户端直接登录并设置密码
mysqladmin -uroot -p$MYSQL_ROOT_PASSWORD password "$NEW_MYSQL_ROOT_PASSWORD"