第一次登陆用临时密码:
grep 'localhost' /var/log/mysqld.log mysql -uroot -p''
修改密码
mysql> set global validate_password_policy=0; # 只验证长度 mysql> set global validate_password_length=6; # 修改密码长度(默认8位) mysql> alter user user() identified by '123456'; # 修改登陆密码
预期交互脚本修改密码
#!/bin/bash temp=`awk -F: '/localhost/{print $4}' /var/log/mysqld.log | awk '{print $1}'` expect << EOF spawn mysql -uroot -p expect ":" {send "$temp "} expect "> " {send "set global validate_password_policy=0; "} expect "> " {send "set global validate_password_length=6; "} expect "> " {send "alter user user() identified by '123456'; "} expect "#" {send "exit "} EOF echo ''