用脚本自动安装mysql5.7.x

很简单的脚本,将安装过程复制过来就可以,写下来只是怕会忘记,以后用起来方便。

vim auto_install_mysql.sh
#!/bin/bash
yum install  -y  wget
wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
rpm -Uvh mysql57-community-release-el6-9.noarch.rpm
yum clean all
sleep 2
yum install mysql-community-server -y
/etc/init.d/mysqld start
chkconfig --level 2345 mysqld on
for i in `grep 'temporary password' /var/log/mysqld.log| awk -F": " '{print $2}'`;
    do
        mysql -uroot -p$i -e "set global validate_password_policy=0;" -b --connect-expired-password
        mysql -uroot -p$i -e "set global validate_password_length=6;" -b --connect-expired-password
        mysql -uroot -p$i -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '******';" -b --connect-expired-password
        /usr/bin/mysqladmin -u root -p$i  password '******' -b --connect-expired-password
        mysql -uroot -p"******" -e "show databases;"
        echo "mysql is install  ok"
done
service mysqld restart
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT  
service iptables save
/etc/init.d/iptables restart

需要加上x权限:

chmod +x auto_install_mysql.sh
./auto_install_mysql.sh

你可能感兴趣的:(mysql,脚本)