One, simple implementation of MySQL one-click installation
Reference:"chapter II" MySQL database based on centos7.3-deployment
This script is conditional on the firewall, and SELinux is already set up:
[Email protected] ~]#CatInstallmysql.SH #!/bin/bash#2018- the-Geneva#旅行者-travel# unloading with maridbYum-Y-Remove mari*RM-rf/var/lib/mysql/*#下载yum源URL = "https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm"wget $URL-P/etc/yum.repos.d/yum-y install/etc/yum.repos.d/ Mysql80-community-release-el7-1.noarch.rpmyum-config-manager--disable Mysql80-communityyum-config-manager-- Enable Mysql57-communityyum-y install Mysql-community-serversystemctl start mysqld systemctl enable Mysqldsystemctl STA Tus mysqldif [$?-eq 0];thenecho-e "Install succefull" fi
Second, modify the MySQL initial password
1) Since mysql5.7 initialization is a password, need to find a password to login, so we directly through the script to modify the password, and achieve login:
[Email protected] ~]#CatI.SH #!/bin/Bashresult="' grep ' temporary password '/var/log/mysqld.log '"P1="' echo $result |awk ' {print $NF} '"Read-P"Please enter the database password:"Num1read-s-p"Please enter the database password:"num2if[$num 1 = $num 2]; Thenmysqladmin-uroot-p"$p 1"Password"$num 1" Echo "passwd Change Successful"MySQL-uroot-P$num1Else
2) Optimize the above script real menu operation:
[Email protected] ~]#CatChangePasswd1.SH #!/bin/Bashfunctioninit_passwd () {result="' grep ' temporary password '/var/log/mysqld.log '"P1="' echo $result |awk ' {print $NF} '"Read-P"Please enter the database password:"Num1read-s-p"Please enter the database password:"num2if[$num 1 = $num 2]; Thenmysqladmin-uroot-p"$p 1"Password"$num 1" Echo "passwd Change Successful"MySQL-uroot-P$num1Else Echo "two times the input password is inconsistent"Exit0fi}functionmenu () {Cat<<EOF-----------Main Menu-----------------1) initializes the database password2) Login Database Q) exit Eofread-P"Please enter the serial number:"num3 Case$num 3inch 1) init_passwd;; 2) MySQL-uroot-p$num1;; Q|q) Exit0 ;; *) Echo "-------Please enter the correct serial number-------"MenuEsac}menu[[email protected]~]#
This script can be used to log into the database effects such as:
This script is rough, is purely for the cluster environment write, post-optimization >>
"Shell daily Practice 6" Initialize install MySQL and change password