本文参考:
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;"
原文地址:https://www.cnblogs.com/llill/p/9478620.html
时间: 2024-11-05 21:33:59