添加 install-myaql.sh

This commit is contained in:
zwb 2024-10-22 12:06:09 +08:00
commit 1741af7189
1 changed files with 26 additions and 0 deletions

26
install-myaql.sh Normal file
View File

@ -0,0 +1,26 @@
#!/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"