cent7安装mysql8后遇到的密码问题
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了 现在我陷入死循环了。
求指点。