1-3 MySQL5.7安装脚本与初始化脚本
Posted llill
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1-3 MySQL5.7安装脚本与初始化脚本相关的知识,希望对你有一定的参考价值。
本文参考:
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安装脚本与初始化脚本的主要内容,如果未能解决你的问题,请参考以下文章