cent7安装mysql8后遇到的密码问题

柴米油盐酱醋0 2018-04-25 08:53:41
1、按照网上教程安装MYSQL没有遇到任何问题。
安装完成之后,
用 grep 'temporary password' /var/log/mysqld.log 命令看到密码

然后mysql -uroot -p
输入密码 提示
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

如果故意输个错误的提示如下
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

按照网上说在my.cnf加入一个参数
skip-grant-tables
重启服务systemctl restart mysqld.service
加入后可以直接mysql -uroot -p 密码直接回车,登录进MYSQL
可以网上搜索到的任何修改密码命令都报错,
如下:
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
这是登录进来了
use mysql;

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
------擦,又报错了,昨天都没报,我加个-A再试一下。
[root@localhost ~]# mysql -uroot -p -A
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Database changed
mysql>
----------------好了
mysql> update user set password=PASSWORD("123456") where user='root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("123456") where user='root'' at line 1
mysql>


----------------试了N多修改密码命令都大概提示上述错误 。
----------------今天搜到原来8的密码认证插件改了-------------------如下
在MySQL8.0.4以前,执行

SET PASSWORD=PASSWORD('[修改的密码]');
就可以更改密码,但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。

因为当前有很多数据库工具和链接包都不支持“caching_sha2_password”,为了方便,我暂时还是改回了“mysql_native_password”认证插件。

在MySQL中执行命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
修改密码验证插件,同时修改密码。

如果想默认使用“mysql_native_password”插件认证,可以在配置文件中配置default_authentication_plugin项
-------------------------------------------------------------------------------------------
我在my.cnf加入default_authentication_plugin=mysql_native_password
执行ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
提示我使用skip-grant-tables了 现在我陷入死循环了。
求指点。
...全文
2272 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
谢版主大人回帖,还不行,如下: [root@localhost ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) ------我在另一个窗口下vi my.cnf 加上skip-grant-tables后重启服务,可正常登录了 [root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.0.11 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> update user set authentication_string=PASSWORD("Lyp@1234") where user='root'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("Lyp@1234") where user='root'' at line 1 mysql> 执行命令报错,我找过好多更新密码的命令,一直在报这个错误。
rucypli 2018-04-25
  • 打赏
  • 举报
回复
1 update user set authentication_string=PASSWORD("Lyp@1234") where user='root'; 2 去掉skip-grant-tables 重启,用Lyp@1234密码登录 3 SET PASSWORD=PASSWORD('[修改的密码]');
  • 打赏
  • 举报
回复
我擦,我真佩服自己的智商!!! [root@localhost log]# grep 'temporary password' /var/log/mysqld.log 2018-04-24T10:03:31.948618Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /vgJp_8Wft+7 我一直输入的密码是 vgJp_8Wft+7 没有前边的/ 刚才试了N次 无意间看到这个细节。。。。 晕死了。

56,685

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧