mysql 8.0.16 winx64及Linux修改root用户密码 的方法
作者:大师在流浪 时间:2024-01-29 00:35:54
连接数据库等基础操作请自行解决哈,本篇是重点记录如何改密码。
一、查询用户密码:
查询用户密码命令:
select host, user, authentication_string from mysql.user ;
host:允许用户登录的ip‘位置'%表示可以远程;
user:当前数据库的用户名;
authentication_string:用户密码(后面有提到此字段);
二、 设置(或修改)用户密码:
默认root密码为空的话 ,下面使用navicat就无法连接(之前我装的5.7好像还可以),所以这里需要修改root的密码。
此乃关键一步。为此被坑了好长时间,后来查阅很多才知道在mysql 5.7.9以后废弃了password字段和password()函数;
authentication_string:字段表示用户密码。
三、修改root密码的步骤:
一、如果当前root用户authentication_string字段下有内容,可先将其设置为空,不然直接进行二步骤。
update user set authentication_string='' where user='root';#密码设置为空
二、使用ALTER修改root用户密码,方法为 ALTER user 'root'@'localhost' IDENTIFIED BY '新密码'。如下:
alter user 'root'@'%' identified with mysql_native_password by 'xxxx';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'mypwd#2019';
或者 alter user 'root'@'localhost' identified with mysql_native_password by 'xxxx';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypwd#2019'
提示:
root@后面是user表的Host字段的内容,新安装默认是localhost, 因为在这增加了远程访问,所以将localhost手动改成了%。
改完之后可执行:flush privileges;
( 重新加载权限表 )
flush privileges;
注意:mysql8.0之后的版本,下面方法已经不适用。切记!!!
UPDATE user SET password=PASSWORD("新密码") WHERE user='用户名';
以上文字如有不妥之处,还请大家详细指正并留言,方便今后大家共同成长;
在此也希望本篇博客能够对大家有所帮助!
来源:https://www.cnblogs.com/aop-liu/archive/2019/07/09/11161277.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
OpenCV imread读取图片失败的问题及解决
![](https://img.aspxhome.com/file/2023/0/92480_0s.png)
mysql 无限级分类实现思路
![](https://img.aspxhome.com/file/2023/7/94737_0s.jpg)
python SSH模块登录,远程机执行shell命令实例解析
gin项目部署到服务器并后台启动的步骤
python字典get()方法用法分析
快速修复损坏的MySQL数据库
Python中的enum的使用方法
![](https://img.aspxhome.com/file/2023/8/134618_0s.png)
Vue实现类似Spring官网图片滑动效果方法
![](https://img.aspxhome.com/file/2023/6/130176_0s.gif)
如何创建SQL Server 2000故障转移群集
Linux下安装mysql的教程详解
centos 6.5下 mysql-community-server. 5.7.18-1.el6安装
Python unittest单元测试框架实现参数化
![](https://img.aspxhome.com/file/2023/5/112025_0s.png)
Python函数式编程之返回函数实例详解
![](https://img.aspxhome.com/file/2023/2/80402_0s.png)
像数艺术
![](https://img.aspxhome.com/file/UploadPic/20102/8/banner-78s.jpg)
PyCharm配置KBEngine快速处理代码提示冲突、配置命令问题
![](https://img.aspxhome.com/file/2023/4/64654_0s.png)
Python基于pillow判断图片完整性的方法
Python快速排序算法实例分析
![](https://img.aspxhome.com/file/2023/4/72014_0s.png)
教你用Type Hint提高Python程序开发效率
Python Django ORM与模型详解
![](https://img.aspxhome.com/file/2023/6/91876_0s.png)