Rapid deployment of MySQL server under [linux]

- Installing MySQL-server, MySQl-client package
- to modify the database user root password
- confirm the MySQL service program runs, root controllable
Description: (1) using the 64-bit RHEL 7 operating system, MySQL database version is 5.7.17
(2) access http://dev.mysql.com/downloads/mysql/, find the MySQL Community Server download page, select the platform "Red Hat Enterprise Linux 7 / Oracle Linux", and then select the 64-bit integrated bundle package download that can.

! # / bin / bash
#AUTHOR: ZHD
#date: 2019-05-19
#function: quickly build MySQL service
#VERSION: 1.0

# Define mysql start function

function mysql_start {
        systemctl restart mysqld
}

Function defined output color #

function cecho  {
        echo -e "\033[$1m$2\033[0m"
}

# Service password set by the user

function secert {
while :
do
        stty -echo
        read -p "Please input password:" p1
        echo " "
        stty echo

        stty -echo
        read -p "Please input password again:" p2
        echo " "
        stty echo
        if [ $p1 = $p2 ];then
                cecho 32 "Set password Successfully!!"
                exit
        else
                cecho 31  "The password set twice is different,Please re-enter!!"
        fi
done
}

# Main program to install MySQL

function install_mysql {
        cd /root/soft/mysql
        cecho 32  "The system is packing,Just a moment,please....."
        yum -y install mysql-community-*.rpm
        cecho 32  "MySQL service is starting,Just a moment,please....."
        mysql_start
        cecho 32  "MySQL service to start successfully!!"
        password=$(grep 'temporary password' /var/log/mysqld.log | tail -1 | awk '{print $11}')
        mysql  --connect-expired-password  -hlocalhost  -uroot  -p$password  -e "alter user root@'localhost' identified by '123qqq...A';" &> /dev/null

        sed -i "4a validate_password_length=6" /etc/my.cnf
        sed -i "4a validate_password_policy=0" /etc/my.cnf
        mysql_start

        mysql --connect-expired-password  -uroot -p123qqq...A  -e 'update mysql.user set authentication_string=password("123456")  where user="root" and host="localhost";' &> /dev/null
        mysql_start
        cecho 32  +++++++++++mysql服务成功搭建!+++++++++

}

install_mysql

Guess you like

Origin blog.csdn.net/qq_44839276/article/details/90412671