#install mysql and init passwd
cd /home/software/
wget -i -c
yum-config-manager -v
if [ $? -ne 0 ];
then
yum -y install yum-utils
echo 「–>[date +"%y-%m-%d %h:%m.%s"
] yum-utils in not defind,begin to install」
fi#選擇安裝mysql版本 這裡預設安裝5.6版本 高於5.6版本初始化資料庫密碼無效
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --disable mysql57-community
sudo yum-config-manager --enable mysql56-community
yum -y localinstall mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
systemctl start mysqld.service
systemctl enable mysqld.service
#資料庫初始化密碼
default_mysql_password=「123456」
while (true)
doread -t 10 -p 「請輸入資料庫密碼:」 set_mysql_password
if [ -z $set_mysql_password ];then
set_mysql_password=""
firead -t 10 -p 「請再次輸入資料庫密碼:」 confirm_mysql_password
if [ -z $confirm_mysql_password ];then
confirm_mysql_password=""
fiif [ $set_mysql_password == $confirm_mysql_password ];then
echo 「密碼設定成功」
if [ set
mysq
lpas
swor
d!="
"];t
hend
efau
ltmy
sqlp
assw
ord=
set_mysql_password != "" ];then default_mysql_password=
setmy
sqlp
ass
word
!=""
];th
ende
faul
tmy
sqlp
ass
word
=set_mysql_password
fibreak
else
echo 「兩次密碼不一致」
fidone
chage_mysql_password=「update user set password=password(『def
ault
mysq
lpas
swor
d′)w
here
user
=′ro
ot′a
ndho
st=′
loca
lhos
t′;"
allo
wnal
lcon
netm
ysql
="gr
anta
llpr
ivil
eges
on∗.
∗to′
root
′@
′default_mysql_password') where user='root' and host='localhost';" allown_all_connet_mysql="grant all privileges on *.* to 'root'@'%' identified by '
defaul
tmy
sqlp
ass
word
′)wh
ereu
ser=
′roo
t′an
dhos
t=′l
ocal
host
′;"a
llow
nal
lco
nnet
mys
ql="
gran
tall
priv
ileg
eson
∗.∗t
o′ro
ot′@
′default_mysql_password』 with grant option;」
update_mysql_password=「flush privileges;」
mysql_username=「root」
mysql_password=""
mysql -u $mysql_username $mysql_password