#################### #数据库装包改密码 #######################
#!/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 database package Change Password script