#1. check if download the mysql rpm package,if not,download
ql_rpm_package=`find / -name "mysql*release*rpm*"`
mysql_rpm_package_name=mysql*release*rpm*
if [ `find / -name "mysql*release*rpm*"|wc -l` -ne0 ];thenecho-e"yes,you have the mysql rpm package,it's in :\n$mysql_rpm_package\n"elseecho-e"you don't have the mysql rpm pakage,now we start download\n------------------------"
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
echo-e"complete download mysql rpm\n"fi#2. check if install local mysql rpm ,if not,installif [ `rpm -qa|grep mysql_rpm_package_name|wc -l` -ge 1 ];thenecho-e"yes,you have installed local mysql rpm:"
rpm -qa | grep mysql_rpm_package_name
echoelseecho-e"begin install rpm kagage\n-------------------------"
yum localinstall mysql57-community-release-el7-11.noarch.rpm
echo-e"complete install mysql rpm package,these are mysql in yum repository list:"
yum repolist enabled|grep mysql
echofi# 3.check if install mysql,if not,installif [ `rpm -qa|grep mysql|wc -l` -gt1 ];thenecho-e"yes,you have installed mysql:"
rpm -qa |grep mysql
echoelseecho-e"you don't install mysql,now we start install mysql\n-----------------------"
yum install mysql-community-server
echo-e"complete install mysql,these are the all installed:"
rpm -qa|grep mysql
echofi#4. start mysqlecho-e"start mysql"
systemctl start mysqld
echo-e"mysql has started\n"#5. set mysql start when we start the CentOSecho-e"set mysql start when we start the CentOS"
systemctl enable mysqld
systemctl daemon-reload
echo-e"set succeed\n"# 6.login mysql use root and initial password
USERNAME=root
INITIAL_PASSWORD=$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
echo-e"your initial mysql password for root is:\n$INITIAL_PASSWORD"echo-e"login mysql: -----------------"
mysql -u$USERNAME -p$INITIAL_PASSWORD << EOF
create database if not exists myapp;
show databases;
EOF
echo-e"\ncomplete login and create database myapp!"