mysql数据库装包改密码脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql数据库装包改密码脚本相关的知识,希望对你有一定的参考价值。
#####################数据库装包改密码#######################
#!/bin/bash
firewall-cmd --set-default-zone=trusted
setenforce 0
#tar -xf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
rm -rf mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
yum -y install perl-Data-Dumper.x86_64 perl-JSON.noarch perl-JSON-PP.noarch
rpm -Uvh mysql-community-*.rpm --nodeps
systemctl restart mysqld
systemctl enable mysqld
yum -y install expect.x86_64
###############取初始密码####################################
first_password=\‘awk ‘/[email protected]:/{print $11}‘ /var/log/mysqld.log
\‘
expect << EOF
spawn mysql -uroot -p$first_password
expect "mysql>" {send "set global validate_password_policy=0;\n"}
expect "mysql>" {send "set global validate_password_length=6;\n"}
expect "mysql>" {send "alter user [email protected] identified by \"123456\";\n"}
expect "mysql>" { send "quit\n"}
EOF
sed -i ‘/^[mysqld]/avalidate_password_policy=0‘ /etc/my.cnf
sed -i ‘/^[mysqld]/avalidate_password_length=6‘ /etc/my.cnf
systemctl restart mysqld
以上是关于mysql数据库装包改密码脚本的主要内容,如果未能解决你的问题,请参考以下文章
修改MySQL密码报错“ERROR 1819 (HY000): Your password does not satisfy the current policy requirements“(代码片段
连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段