#!/bin/bash
#created by Kevin2016/03/30, modify 2016/04/20#-----------------------------------------------------------------------------# Installation Scriptfor the auto-deployment EMM(Linux edition)
#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# shell script toinstall MySQL (default version mysql-community-5.7.11)echo "-----------------------start install mysql----------------------"# Add to mysql user and mysql groupif [ `grep "mysql" /etc/passwd | wc -l` -eq 0 ];then
echo "adding user mysql"groupadd mysql
useradd-r -g mysql mysqlelse
echo "mysql user is exist"
fi# check installed mysql or notfor i in `rpm -qa | grep "mysql"`dorpm-e --allmatches $i --nodepsdone# Remove pre-installed on OS MariaDB ifexistsfor i in $(rpm -qa | grep mariadb | grep -v grep)do
echo "Deleting rpm -->"$i
rpm-e --nodeps $idone# Install mysqlserver
rpm-ivh mysql-community-server-5.7.11-1.el7.x86_64.rpm mysql-community-client-5.7.11-1.el7.x86_64.rpm mysql-community-common-5.7.11-1.el7.x86_64.rpm mysql-community-libs-5.7.11-1.el7.x86_64.rpm
# check the installtation was successful or not
rpm-qa |grep "mysql"
if [ $? != 0 ];then
echo "mysql install fail"| tee$mysql_instlog
exit1
else
echo "mysql isntall success"| tee$mysql_instlogfi# modify configuration files
cd/etc/
echo "character_set_server=utf8" >>my.cnf
# startup the mysql
systemctl start mysqld
systemctl status mysqld/etc/init.d/mysqld start/etc/init.d/mysqld stopecho "MySQL Server install successfully!"# configurationcat /etc/my.cnfsed -i '/mysqld/a\skip-grant-tables' /etc/my.cnf
systemctl restart mysqld
# mysql-u root mysql
mysql-u root mysql -e "use mysql;"# use mysql
# update mysql.user set authentication_string=password('root') where user='root';
mysql-u root mysql -e "update mysql.user set authentication_string=password('root') where user='root' ;"mysql-u root mysql -e "flush privileges;"
cat /etc/my.cnfsed -i '/skip-grant-tables/s/^/#/' /etc/my.cnf
# mysql-u root -p
# SET PASSWORD= PASSWORD('root');
mysql-u root -proot --connect-expired-password -e "SET PASSWORD = PASSWORD('root');"# mysql-u root mysql
# use mysql;
mysql-u root -proot -e "use mysql;"# update user set host= '%' where user ='root';
mysql-u root -proot -e "update user set host = '%' where user ='root';"#selecthost, user from user;
mysql-u root -proot -e "select host, user from user;"# exit
mysql-u root -proot -e "source /usr/src/tools/user.sql;"mysql-u root -proot -e "source /usr/src/tools/emm_saas_base.sql;"# create a new database, name as"emm_saas_base"# mysql-u root -p
# create database emm_saas_base;
# mysql-u root -proot -e "create database emm_saas_base;"# show databases;
# mysql-u root -proot -e "show databases;"# initdb
#for x in find . -name "*.sql"#dosource emm_saas_base.sql
#done# create user&authentication
# mysql-u root -p
# CREATE USER'emm'@'%' IDENTIFIED BY 'emm';
# GRANT ALL ON*.* TO 'emm'@'%';
# show userinthe DB
#selecthost,user from mysql.user;
mysql-u root -proot -e "select host,user from mysql.user;"
echo "The MySQL install and config complete!"