设为首页 加入收藏

TOP

CentOS Linux 7.5 编译安装 MySQL 8.0.12 及修改密码问题(二)
2019-02-28 00:08:30 】 浏览:311
Tags:CentOS Linux 7.5 编译 安装 MySQL 8.0.12 修改 密码 问题
h.rpm
yum repolist enabled|grep "mysql.*-community.*"
yum repolist all|grep mysql
yum install mysql-community-server
systemctl enable mysqld
systemctl start mysqld
netstat -lntup|grep 3306


#查看随机生成的密码


grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p


#修改密码,密码必须要由大小写字母、数字和特性字符组成


alter user 'root'@'localhost' identified by 'PJY@123.com';
select version();


MySQL5.7和之前的用户修改密码方式:


mysql -uroot -e "Set password=password(‘123’);"
mysql -uroot -p123.com -e "use mysql;update user set authentication_string=password('456') where user='root';"
update mysql.user set authentication_string=password("123") where user='root';


以上三种方法在MySQL8.0以后版本中将不能使用,如果使用了将会导致在正确修改密码是报如下错误:


mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'


如遇上以上问题请使用update语句先清空authentication_string字段,然后再修改密码即可


update user set authentication_string='' where user='root';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';


所以特别提醒童鞋们:


MySQL8.0后请使用alter修改用户密码,因为在MySQL8.0以后的加密方式为caching_sha2_password,如果使用update修改密码会给user表中root用户的authentication_string字段下设置newpassowrd值,当再使用alter user 'root'@'localhost' identified by 'newpassword'修改密码时会一直报错,必须清空后再修改,因为authentication_string字段下只能是MySQL加密后的43位字符串密码,其他的会报格式错误,所以在MySQL8.0以后能修改密码的方法只能是:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇phpMyAdmin创建MySQL的存储过程 下一篇Redis 过期键删除策略

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目