1.7. 查询用户密码:mysql
查询用户密码命令:mysql> select host,user,authentication_string from mysql.user;sql
host: 容许用户登陆的ip‘位置'%表示能够远程;数据库
user:当前数据库的用户名;ide
authentication_string: 用户密码(后面有提到此字段);函数
1.8. 设置(或修改)root用户密码:加密
默认root密码为空的话 ,下面使用navicat就没法链接,因此咱们须要修改root的密码。spa
这是很关键的一步。此处踩过N多坑,后来查阅不少才知道在mysql 5.7.9之后废弃了password字段和password()函数;authentication_string:字段表示用户密码。.net
下面直接演示正确修改root密码的步骤:插件
1、若是当前root用户authentication_string字段下有内容,先将其设置为空,不然直接进行二步骤。code
use mysql; update user set authentication_string='' where user='root'
2、使用ALTER修改root用户密码,方法为 ALTER user 'root'@'localhost' IDENTIFIED BY '新密码'。以下:
ALTER user 'root'@'localhost' IDENTIFIED BY 'Cliu123#'
此处有两点须要注意:
一、不须要flush privileges来刷新权限。
二、密码要包含大写字母,小写字母,数字,特殊符号。
修改为功; 从新使用用户名密码登陆便可;
注意: 必定不要采起以下形式该密码:
use mysql; update user set authentication_string="newpassword" where user="root";
这样会给user表中root用户的authentication_string字段下设置了newpassword值;
当再使用ALTER USER 'root'@'localhost' IDENTIFITED BY 'newpassword'
时会报错的;
由于authentication_string字段下只能是mysql加密后的41位字符串密码;其余的会报格式错误;
*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE
至此,安装mysql和修改root密码告一段落。
开始navicat for mysql篇。
帐号密码都正确,链接报错1251。OK 咱们先来看看这个改动:
在MySQL 8.04前,执行:SET PASSWORD=PASSWORD('[新密码]');可是MySQL8.0.4开始,这样默认是不行的。由于以前,MySQL的密码认证插件是“mysql_native_password”,而如今使用的是“caching_sha2_password”。
so,咱们这里须要再次修改一次root密码。
先登陆进入mysql环境:执行下面三个命令。(记得带上分号)
use mysql; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'; FLUSH PRIVILEGES;
其余删除用户,添加用户
delete from user where user='jack'and host='localhost'; flush privileges; create user 'jack'@'localhost' identified by 'ddd';
修改远程链接:
update user set host='%' where user='root'; flush privileges;
转 : https://www.jb51.net/article/142025.htm