1. 程式人生 > >1-3 MySQL5.7安裝腳本與初始化腳本

1-3 MySQL5.7安裝腳本與初始化腳本

print $nf root base del dir file error service

本文參考:

http://www.unixfbi.com/1.html

MySQL5.7安裝腳本

# cat mysql.sh 

groupadd mysql
useradd -g mysql  -d /usr/local/mysql  -s /sbin/nologin -M  mysql
id mysql
yum install libaio -y
mkdir /opt/mysql/ -pv 
tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz  -C /opt/mysql/
ln -s /opt/mysql/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql

mkdir /data/mysql/mysql3306/{data,logs,tmp} -pv
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data

cp my.cnf  /etc/my.cnf

cd /usr/local/mysql
./bin/mysqld --defaults-file=/etc/my.cnf   --initialize

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

PASSWD=$(grep ‘password is‘ /data/mysql/mysql3306/data/error.log  | awk ‘{print $NF}‘)
mysql -uroot -p"$PASSWD" --connect-expired-password -e "alter user user() identified by ‘llill2019‘;"
mysql -uroot -p‘llill2019‘ -e "show databases;"

  

MySQL 初始化腳本

作用:每次MySQL功能測試完畢後還原MySQL至初始化狀態


[[email protected]_2_33]cat /data/mysql/initmysql.sh 
#!/bin/bash
echo "*******delete the related folder of mysql*******"
service mysqld restart
service mysqld stop
rm -rf /data/mysql/mysql3306/data/*
rm -rf /data/mysql/mysql3306/logs/*
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data
echo "*******initialize the mysql app*******"
cd /usr/local/mysql
./bin/mysqld --defaults-file=/etc/my.cnf   --initialize
echo "*******add the auto-start service for mysql*******"
rm -rf /etc/init.d/mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
echo "*******start the mysyql servcie and set password as ‘llill2019‘*******"
/etc/init.d/mysqld start
PASSWD=$(grep ‘password is‘ /data/mysql/mysql3306/data/error.log  | awk ‘{print $NF}‘)
mysql -uroot -p"$PASSWD" --connect-expired-password -e "alter user user() identified by ‘llill2019‘;"
mysql -uroot -p‘llill2019‘ -e "show databases;"

  

1-3 MySQL5.7安裝腳本與初始化腳本