centos 安装mysql8.0 并修改root密码,解决密码不符合当前策略要求

yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm -y
# yum localinstall是用来安装本地rpm包的命令,首先rpm包要先下载到本地,然后在本地目录执行yum localinstall *.rpm

yum install mysql-community-server -y
# 安装mysql8

grep 'temporary password' /var/log/mysqld.log
# 查看root用户密码root@localhost: #JN3*dNuh=iv; 密码是:#JN3*dNuh=iv

mysql -uroot -p#JN3*dNuh=iv -e" set global validate_password.policy=0 ; set global validate_password.length=6; use mysql;alter user 'root'@'localhost' identified by 'eisc.cn';"
# 解决密码不符合当前策略要求:密码最小长度(6)set global validate_password.policy=0 ; set global validate_password.length=6;
# 进入mysql数据库,更新root再本地的密码为:eisc.cn

user="eisc";database="eisc";passwd="eisc.cn"   ; mysql -uroot -peisc.cn -e "create database $database character set utf8 collate utf8_bin; create user '$user'@'localhost' identified by '$passwd';create user '$user'@'%' identified by '$passwd' ; show databases;SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS ListUsername FROM mysql.user where User='$user';           grant select,create,update,delete on *.* to '$user'@'localhost' ; grant select,create,update,delete  on *.* to '$user'@'%' ; SHOW GRANTS FOR $user;FLUSH PRIVILEGES;"
# 创建数据库,创建远程和本地用户,授权用户,查看权限
# mysql 8 只能先创建用户,再进行授权。 生效(刷新权限)
# 撤销所有授权:revoke privileges on *.* from 'eisc'@'localhost'

user="eisc";database="eisc";passwd="eisc.cn"   ; mysql -uroot -peisc.cn -e "drop database $database; drop user '$user'@'localhost' ;drop user '$user'@'%'; "
# 一键删除:数据库,用户

user="root";database="eisc";passwd="eisc.cn"   ; mysql -uroot -paaaassss -e "use mysql;select user,authentication_string from user; alter user '$user'@'localhost' identified by '$passwd'; alter user '$user'@'%' identified by '$passwd'; " 
# 更新root 用户密码为:eisc.cn 

 mysql -uroot -peisc.cn -e "select now();"
# 使用新密码登录数据库查看时间



上一篇:mysql 5 or 8 数据库管理,破解管理员密码,创建用户和数据库,开放远程登录,一键删除用户和数据库,shell脚本自动化


下一篇:mysql 忘记root密码破解root密码破解所有用户密码,shell脚本