springboot整合mybatis报错:Access denied for user ''@'localhost' (using password: YES)

报错:Springboot整合mybatis,连不上数据库

问题1:mysql忘记密码了

解决:重置用户root密码

1.在mysql安装目录下找到配置文件  my.ini

2.修改mysql安装目录下的my.ini文件 

搜索[mysqld],在下一行加上skip-grant-tables(跳过权限表)

3.cmd(管理员模式),重启mysql服务 

输入命令

①net stop mysql

②net start mysql 

如果报错:服务名不对,就去任务管理器中找到mysql服务 ,我的是MySQL

springboot整合mybatis报错:Access denied for user ''@'localhost' (using password: YES)

 

那么命令就是 net stop MySQL ,net start MySQL 

4.登录mysql服务器

springboot整合mybatis报错:Access denied for user ''@'localhost' (using password: YES)

 

 

 

C:\Users\dell>mysql -uroot -p

mysql> use mysql                    #使用mysql数据库

mysql> update user set password=PASSWORD("123456") where User=‘root‘  #更新用户密码

mysql>flush privileges             #刷新权限

mysql> quit 

然后删掉my.ini中的skip-grant-tables,重启mysql服务器,即可登录root

 问题2:误删用户 root@localhost

springboot整合mybatis报错:Access denied for user ''@'localhost' (using password: YES)

 

select host,user,password from mysql.user; 查了一下发现只剩root@%了

解决:

1.创建普通用户

2.给创建出的用户授权

命令如下:

能登录 有所有权限的用户的用下面的命令

INSERT INTO mysql.user(Host, User, password, ssl_cipher, x509_issuer, x509_subject) VALUES (‘localhost‘, ‘root‘, PASSWORD(‘123456‘), ‘‘, ‘‘, ‘‘);

grant all privileges on *.* to ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;

能登录的用户没有权限(没有WITH GRANT OPTION的)

直接进mysql.user表修改用户信息(skip-grant-tables)

INSERT INTO mysql.user(Host, User, password, ssl_cipher, x509_issuer, x509_subject) VALUES (‘localhost‘, ‘root‘, PASSWORD(‘123456‘), ‘‘, ‘‘, ‘‘);

UPDATE mysql.user SET  Select_priv =‘Y‘, Insert_priv=‘Y‘, Update_priv=‘Y‘, Delete_priv =‘Y‘,Create_priv=‘Y‘, Drop_priv=‘Y‘, Reload_priv=‘Y‘,Shutdown_priv =‘Y‘, Process_priv =‘Y‘, File_priv =‘Y‘, Grant_priv =‘Y‘, References_priv =‘Y‘, Index_priv =‘Y‘, Alter_priv =‘Y‘, Show_db_priv =‘Y‘, Super_priv =‘Y‘, Create_tmp_table_priv =‘Y‘, Lock_tables_priv =‘Y‘, Execute_priv =‘Y‘, Repl_slave_priv =‘Y‘, Repl_client_priv =‘Y‘, Create_view_priv =‘Y‘, Show_view_priv =‘Y‘, Create_routine_priv =‘Y‘, Alter_routine_priv =‘Y‘, Create_user_priv =‘Y‘, Event_priv =‘Y‘, Trigger_priv =‘Y‘, Create_tablespace_priv =‘Y‘ WHERE Host =‘localhost‘ and  User =‘root‘; 

一个用户都没有,步骤同上,insert user ,update 用户权限

最后查权限 ,root@localhost有 ALL PRIVILEGES ,WITH GRANT OPTION 可以给别的用户授权~

 

springboot整合mybatis报错:Access denied for user ''@'localhost' (using password: YES)

 

最后检查配置文件application.yml ,找到原因了,属性写错  

解决:data-username 改成 username

springboot整合mybatis报错:Access denied for user ''@'localhost' (using password: YES)

 

 

 

 

 

 

springboot整合mybatis报错:Access denied for user ''@'localhost' (using password: YES)

上一篇:mysql系列纠错;


下一篇:《Linux/Unix系统编程手册》读书笔记5