MySQL 8.0.16 Community Server 密码错误重置处理 | 您所在的位置:网站首页 › mysql查看当前用户密码命令 › MySQL 8.0.16 Community Server 密码错误重置处理 |
mysql 版本:Server version: 8.0.16 MySQL Community Server 错误提示: # 登录 mysql,输入密码后 mysql -u root -p mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)提示需要密码验证,访问拒绝,密码错误,正确密码未知,需重置密码。 解决办法: # 默认情况下,mysql 安装后,如果密码为空,会自动创建随机密码 # 如果密码错误,无法登录,打开 my.ini 的将 skip-grant-tables 放开,linux 环境下是 /etc/my.cnf,表示无认证登录 mysql -u root -p# 查看 mysql 日志文件所在文件置,在 error log 中,有为 root 用户随机生成了一个密码 select @@log_error;# 通过 grep 命令找到随机密码 grep "password" /var/log/mysqld.log 2019-06-29T14:00:02.600036Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Se4%Fa3r5_rP# 登录,用该密码登录到服务端后,必须马上修改密码 mysql -u root -pSe4%Fa3r5_rP#(或者,直接跳过上述方式,直接修改密码) # 进入 mysql use mysql;# 查看 user 信息 select host,user,authentication_string from user;# 如果当前 root 用户 authentication_string 字段下有内容,先将其设置为空 update user set authentication_string='' where user='root'# 密码要包含大写字母,小写字母,数字,特殊符号 ALTER user 'root'@'localhost' IDENTIFIED BY 'Db_user_2019#'#改完后退出,再登录即可 mysql -u root -pDb_user_2019#注意:在 mysql 5.7.9 以后废弃了 password 字段和 password () 函数;authentication_string: 字段表示用户密码。 修改成功后,再次到 my.ini 文件中的将 skip-grant-tables 注释,开启认证登录,重启 mysql 服务; navicat 无法连接到 mysql修改密码后,navicat 无法连接到 mysql, 账号密码都正确,连接报错 1251,就连项目程序中也无法连接到 mysql 数据库。 在 MySQL 8.04 前,执行:SET PASSWORD=PASSWORD ('[新密码]'); 但是 MySQL8.0.4 开始,这样默认是不行的。因为之前,MySQL 的密码认证插件是 “mysql_native_password”,而现在使用的是 “caching_sha2_password”。 需要再次修改一次 root 密码。 解决办法: # 登录进入 mysql 环境 mysql -u root -pDb_user_2019## 定位到 mysql 数据库 use mysql;# 重新修改密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Db_user_2019#';# 刷新权限 FLUSH PRIVILEGES; |
CopyRight 2018-2019 实验室设备网 版权所有 |