银河麒麟服务器、centos7服务器mysql离线安装:通过获取临时密码进行登录修改新密码

离线安装脚本

    cd /home/zenglg/mysql5.7
    # 判断mysql是否安装
    # 下面这种方法必须是rpm安装的判断才有效,不通用
    # IS_INSTALLED=$(rpm -qa |grep mysql)
    # if [ $? -eq 0 ]
    # 下面的判断方法是查询版本号,比较通用
    SQL_VERSION=`mysql -V | grep -i -o -P '5.7.41'`
    if [ $SQL_VERSION == "5.7.41" ];then
        echo 'mysql installed';
    else
        {
            #卸载mariadb
            rpm -e --nodeps mariadb-libs
            #安装mysql
            rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
            cd /home/zenglg/mysql5.7/perl
            rpm -ivh perl-5.16.3-297.el7.x86_64.rpm perl-libs-5.16.3-297.el7.x86_64.rpm perl-macros-5.16.3-297.el7.x86_64.rpm perl-threads-shared-1.43-6.el7.x86_64.rpm perl-threads-1.87-4.el7.x86_64.rpm perl-constant-1.27-2.el7.noarch.rpm perl-Carp-1.26-244.el7.noarch.rpm perl-File-Temp-0.23.01-3.el7.noarch.rpm perl-File-Path-2.09-2.el7.noarch.rpm perl-PathTools-3.40-5.el7.x86_64.rpm perl-Exporter-5.68-3.el7.noarch.rpm perl-Socket-2.010-5.el7.x86_64.rpm perl-Storable-2.45-3.el7.x86_64.rpm perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm perl-Filter-1.49-3.el7.x86_64.rpm perl-Getopt-Long-2.40-3.el7.noarch.rpm perl-Pod-Simple-3.28-4.el7.noarch.rpm perl-Text-ParseWords-3.29-4.el7.noarch.rpm perl-Time-HiRes-1.9725-3.el7.x86_64.rpm perl-Time-Local-1.2300-2.el7.noarch.rpm perl-Pod-Escapes-1.04-297.el7.noarch.rpm perl-Pod-Usage-1.63-3.el7.noarch.rpm perl-Encode-2.51-7.el7.x86_64.rpm perl-Pod-Perldoc-3.20-4.el7.noarch.rpm perl-podlators-2.5.1-3.el7.noarch.rpm perl-HTTP-Tiny-0.033-3.el7.noarch.rpm perl-parent-0.225-244.el7.noarch.rpm

            cd /home/zenglg/mysql5.7/
            rpm -ivh perl-Data-Dumper-2.145-3.el7.x86_64.rpm 
            rpm -ivh numactl*
            rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm 
            rpm -ivh mysql-community-libs-*
            rpm -ivh mysql-community-devel-5.7.41-1.el7.x86_64.rpm
            rpm -ivh net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
            rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm
            rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm  
            
            echo "启动mysql 服务"
            sudo systemctl start mysqld.service
            
            SQL_VERSION=`mysql -V | grep -i -o -P '5.7'`
            if [ $SQL_VERSION == "5.7" ];then
                echo "check msyql install ok!"
            else
                echo -e "\033[31m Msyql install error, Please install it manually \033[0m" 
                exit 0
            fi
            
         
            # get mysql temp password
            TEMP_PWD=`grep 'password' /var/log/mysqld.log |head -n 1 |grep -oE "localhost:(.+)$" | grep -i -o -P 'localhost: \K.+'`
            echo $TEMP_PWD
            
            # get mysql sock file 
            SOCK=`netstat -ln | grep mysql | head -n 2 | awk '{print $9}'`
            PORT="3306"
            USER="root"
            # modify set your ownpwd
            PASSWORD="Zenglg2012!@#"
            WRAPPWD="\"Zenglg2012!@#\""
            
            # modify password  
            mysql --connect-expired-password -p$TEMP_PWD -S $SOCK -e 'alter user user() identified by '$WRAPPWD
            
            echo "modify database password ok! new password: $PASSWORD"
            
            #mysql开启远程访问
            mysql  -uroot -p'Zenglg2012!@#' -e"grant all privileges on *.* to 'root'@'%' identified by 'Zenglg2012!@#';"
            mysql  -uroot -p'Zenglg2012!@#' -e"flush privileges;"
            echo "开启远程访问"
        }
    fi

离线安装流程

银河麒麟服务器、centos7服务器mysql离线安装:通过获取临时密码进行登录修改新密码_第1张图片

 

你可能感兴趣的:(服务器,mysql,运维)