Install_CentOS7_MySQL57_multi_instance.sh
#!/bin/bash
#请提前准备好参数文件my.cnf
PORT=3307
InitMySQL()
{
mkdir -p /app/mysqldata/{$PORT/{data,tmp,binlog,redolog,undolog},backup,scripts}
####################################################
chown -R mysql:mysql /app/mysqldata
/usr/local/mysql/bin/mysqld --defaults-file=/app/mysqldata/$PORT/my.cnf --initialize --user=mysql
/usr/local/mysql/bin/mysql_ssl_rsa_setup --defaults-file=/app/mysqldata/$PORT/my.cnf
####################################################
echo "start mysqld"
/usr/local/mysql/bin/mysqld_safe --defaults-file=/app/mysqldata/$PORT/my.cnf &
sleep 5
echo "update root password"
tmppasswd=`grep password /app/mysqldata/$PORT/error.log | awk '{print $NF}'`
/usr/local/mysql/bin/mysql -uroot -p$tmppasswd -S /app/mysqldata/$PORT/mysql.sock --connect-expired-password -e "set password=password('msds007')"
/usr/local/mysql/bin/mysql -uroot -pmsds007 -S /app/mysqldata/$PORT/mysql.sock -e "grant all on *.* to dba_user@'%' identified by 'msds007'"
/usr/local/mysql/bin/mysql -uroot -pmsds007 -S /app/mysqldata/$PORT/mysql.sock -e "flush privileges"
/usr/local/mysql/bin/mysql -uroot -pmsds007 -S /app/mysqldata/$PORT/mysql.sock -e "select user,host,authentication_string from mysql.user"
}
InitMySQL