Mysql8.0.13 登录报1045(28000)错误

Mysql8.0.13 登录报1045(28000)错误,第1张

mysql-8.0.13 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

一、修改root密码

mysql> update mysql.user set authentication_string="123456" where user="root"

或:mysql>update mysql.user set authentication_string="123456" where user="root" and host='localhost'

#刷新权限(必须步骤)

mysql>flush privileges

#查询密码是否生效:

mysql>select host,user,authentication_string from mysql.user

mysql-8.0.13修改密码后mysql>quit  再次登录。

>mysql - u root -p

password:123456 

报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

找到一种解决方法:

1、cmd-1窗口:无密码启动mysql服务

mysqld --console --skip-grant-tables --shared-memory ;

#--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。

2、无密码登录,再次修改密码。

再开一个CMD窗口(前一个CMD窗口已经不能动了),转到mysql\bin目录

>mysql -u root -p

->密码不输入直接enter

#修改密码为空

mysql>UPDATE mysql.user SET authentication_string='' WHERE user='root'

mysql>flush privileges    

myslq>quit   

#再次登录无密码登录

>mysql - u root -p

Enter password: 

#enter不输入密码进入mysql

------------------------------------------------------------------------------------

查询网上资料,可能是MySQL8.0的caching_sha2_password问题,再来试试

MySQL8.0采用了新的更安全的验证方式,原有修改密码方法修改密码后无法登录

mysql>update mysql.user set authentication_string="123456" where user="root" and host='localhost'

1、首先查询用户

mysql>select host,user,plugin,authentication_string from mysql.user

2、修改密码和密码方式

mysql>ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'

mysql>flush privileges

3、退出再次登录,成功。

或者也可以修改密码后再修改plugin

1、mysql>update mysql.user set authentication_string="123456" where user="root" and host='localhost'

2、mysql>UPDATE mysql.user SET plugin='mysql_native_password' WHERE user='root'

具体步骤:windows-mysql无法登录,修改密码

1、首先关闭正在运行的MySQL服务。 

2、打开CMD窗口,转到mysql\bin目录。 

3.、输入 mysqld --console --skip-grant-tables --shared-memory ;。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。

4、再开一个CMD窗口(前一个窗口已经不能动了),转到mysql\bin目录。 

5. 输入mysql -u root -p回车,出现MySQL提示符 >。  

6. 进行修改密码:

ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'

# plugin需要改成: mysql_native_password

7. 刷新权限(必须步骤):flush privileges 。 

8. 退出 quit。 

9. 再次访问,使用用户名root和新密码123456登录。 

#启动mysql服务    net start mysql

#停止mysql服务    net stop mysql

#登录mysql   mysql -u root  -p

#查询用户信息 

mysql>select host,user,plugin,authentication_string from mysql.user

#修改密码:

mysql >ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY it'123456'

#退出  mysql>quit

解决方法:

第一步:如果mysql服务正在进行,将之停止。

第二步:在终端中以管理员权限启动mysqld_safe,命令如下:

sudo/usr/local/mysql/bin/mysqld_safe--skip-grant-tables

执行结果如下:

 mysqld_safe Logging to'/usr/local/mysql/data/lyqdeMacBook-Pro.local.err'.2016-06-12T08:29:17.6NZ mysqld_safe Starting mysqld daemon with databasesfrom/usr/local/mysql/data

第三步:不要关闭当前的终端窗口,新建一个终端窗口,输入如下命令,回车登录mysql

/usr/local/mysql/bin/mysql

登录后,看到欢迎信息:

看到结果:

Reading table informationforcompletion of table and column names

You can turn offthisfeature togeta quicker startup with -A

Database changed

mysql>

然后,更新root的密码,SQL如下:

mysql>update usersetauthentication_string=password('root')whereHost='localhost'and User='root'

注意:

①有的版本的mysql中,密码可能存储在password字段中,可以使用"describe user"命令来查看下表结构再 *** 作

②authentication_string的值一定通过password函数来计算(password('root'))

执行结果如下:

Query OK,1row affected,1warning (0.01sec)

Rows matched:1Changed:1Warnings:1

退出mysql(执行sql语句:exit)

最后一步:将mysqld_safe进程杀死,重启mysqld。

错误如下:1045 Access denied for user 'root'@'localhost' (using password:YES)

想起来有可是在navicat添加的root@'%'用户,可能密码和现在新版本5.7的加密不同了,导致密码不对.

所以解决方法是更新用户密码.

注意5.7版本密码保存的列是 authentication_string ,密码要用函数password加密.

更新密码的SQL是 update user set authentication_string=password('密码') where user="root"

下面是Windows平台下 *** 作步骤:

配置文件my.ini ,在mysqld下面添加skip-grant-tables,意思是可以直接回车登录,保存退出。重启mySQL,然后运行cmd

输入mysql -u root -p就可以不用密码登录了,出现password:的时候直接回车可以进入。

1.切换到mysql数据库:use mysql

2.给root用户设置新密码,

mysql>update user set authentication_string=password('密码') where user="root"

3.刷新数据库mysql>flush privileges

4.再修改my.ini,把刚加入的"skip-grant-tables"这行删除或者添加#注释,保存退出再重启mysql服务就可以了。

一些参考命令

#删除之前配置 drop user 'root' @ '%'

#配置远程登录 CREATE USER 'root' @ '%' IDENTIFIED BY password( '你的密码')

#授权 GRANT ALL ON *.* TO 'root' @ '%'

#更新权限 flush privileges

#查看用户,主机,加密方法 select user,host,plugin from user


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5907457.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-07
下一篇 2023-03-07

发表评论

登录后才能评论

评论列表(0条)

保存