shell 指令碼安裝mysql 支援手動輸入密碼

2021-10-03 12:29:03 字數 3115 閱讀 1578

#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=

setm​y

sqlp

​ass

word

!=""

];th

ende

faul

tm​y

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

tm​y

sqlp

​ass

word

′)wh

ereu

ser=

′roo

t′an

dhos

t=′l

ocal

host

′;"a

llow

na​l

lc​o

nnet

m​ys

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

$chage_mysql_password

$update_mysql_password

$allown_all_connet_mysql

eofif [ $? -eq 0 ];then

echo 「修改資料庫密碼成功!!!」

fiunset default_mysql_password

unset set_mysql_password

unset confirm_mysql_password

unset chage_mysql_password

unset allown_all_connet_mysql

unset update_mysql_password

unset mysql_username

unset mysql_password

mysql備份shell指令碼

bin bash mysql server login info muser root mpass root mhost localhost mysql which mysql mysqldump which mysqldump dbname test bak backup mysql gzip w...

mysql備份shell指令碼

bin bash 要備份的資料庫名,多個資料庫用空格分開 databases test 備份檔案要儲存的目錄 basepath usr local mysqlbak if d basepath then mkdir p basepath fi 迴圈databases陣列 for db in docd...

Shell備份MySQL指令碼

bin bash backup database mysql備份指令碼,自動化備份,定時任務備份,linux centos redhat 正式環境 全量備份 單庫備份 單錶備份 by lumia98 vip.qq.com 適用於生成環境備份指令碼 備份開始時間 echo start date y m...