shell脚本批量设置mysql5.7 root密码
在上一篇文章centos7单机安装mysql多实例中,脚本设置mysql的root密码会失败,在这篇文章里,我单独把设置密码的脚本提取出来了,配合安装脚本一起使用.
系统:centos 7.x(64位)
脚本内容:
cat /root/soft_shell/mysql_password_change.sh
#!/bin/bash read -p "Enter mysql password": newpasswd sed -i "s/rocdk890/$newpasswd/g" /etc/init.d/mysqld_multi chmod +x /etc/init.d/mysqld_multi read -p "Number of mysql": number for i in $( seq 1 $number );do /usr/local/mysql/bin/mysqld_multi --defaults-extra-file=/etc/my.cnf start ${i} /usr/local/mysql/bin/mysql -u root -S /data/mysql${i}/mysql.sock -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$newpasswd';" /usr/local/mysql/bin/mysql -u root -S /data/mysql${i}/mysql.sock -e "flush privileges;" done echo -e "\033[40;31mMySQL password-changing completed!\033[40;37m"
ps:
本脚本只针对之前的一键安装多实例的脚本使用.
本脚本不能重置有root密码的mysql.
请大家注意这两点哦.
评论: