mysql 57 下载+配置脚本

复制运行即可,可以输入修改的数据库密码,若跳过设置,默认将密码修改为123456。

#!/bin/bash
echo "this script is for install mysql5.7-server and change passwd"
function yum_repo(){
    cat >/etc/yum.repos.d/mysql-community.repo<<EOF
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-\$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-\$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
EOF
    yum makecache fast
}

function install_mysql57(){
    yum install -y mysql-server
    systemctl start mysqld
    systemctl enable mysqld
    systemctl status mysqld
}

function get_new_passwd(){
    while :
    do
        read -s -p $'Please input new mysql password : \n' passwd1
        if [ x"$passwd1" = "x" ];then
                echo 'use default passwd 123456'
                newpasswd=123456
                break
        fi
        read -s -p $'Please re input mysql password : \n' passwd2
        if [ $passwd1 != $passwd2 ];then
                echo "The password is inconsistent, please retry"
        else
                newpasswd=$passwd1
                break
        fi
    done
}

function init_sql(){
    get_new_passwd
    cat >~/.init.sql<<EOF
use mysql;
update user set host = '%' where user = 'root';
ALTER USER 'root'@'%' IDENTIFIED BY '$newpasswd';
flush privileges;
EOF
}

function passwd_policy(){
    cat >>/etc/my.cnf<<EOF
plugin-load=validate_password.so
validate-password=OFF  
EOF
    systemctl restart mysqld
}

function get_init_passwd(){
    init_passwd=`grep 'temporary password' /var/log/mysqld.log | awk '{ print $11 }'`
}

function init_mysql(){
    passwd_policy
    get_init_passwd
    /usr/bin/mysql -uroot -p$init_passwd < ~/.init.sql
    echo "mysql initialization is completed new passwd is $newpaaswd"
}

function main(){
    yum_repo
    install_mysql57
    if [ $? != 0 ];then
        echo "download or install mysql failed"
        exit 1
    else
        init_mysql
    fi
}

touch ~/.install_mysql57.log
main | tee -a  ~/.install_mysql57.log
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值