mysql Access denied for user 错误处理

 

 

MySQL中出现连接错误:
               ERROR 1045 (28000): Access denied for user
----------------------------------------------------------------------------------
1.添加用户
shell>mysql
mysql>use mysql
mysql>grant all privileges on *.* to 'test' identified by 'test' with grant option;
mysql>flush privileges;
[也可以使用下面两种方式建立用户]
------------------------
  $1直接操作mysql.user这张表;
  $2使用DDL语言,
    定义用户:create user test identified by 'test';
    删除用户:drop user test
------------------------
 
2.使用test登录(总是无法连接)
shell>mysql -u test -p
ERROR 1045 (28000): Access denied for user 'test'@'localhost' (using password: YES)
 
 
3.查看user表,我们会发现user表中的user字段有NULL
mysql> select host,user from user;
+------------------+------+
| host             | user |
+------------------+------+
| %                | test | 
| localhost        |      | 
| localhost        | root | 
| test.saeg.com.cn |      | 
| test.saeg.com.cn | root | 
+------------------+------+
5 rows in set (0.00 sec)
 
4.删除user.user中值为NULL的,或更新NULL为test
   4.1)delete from user where user is NULL
   4.2)update user set user='test' where user is NULL

 

 

5.参看用户权限

 show grants for root@'localhost';

 

+------------------------------------------------------------------------------------------------------------------------------------------------+

 

 

 

 

 

 

| Grants for test@%                                                                                                              |

+------------------------------------------------------------------------------------------------------------------------------------------------+

 

 

 

 

 

 

| GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*dfg' WITH GRANT OPTION |

+------------------------------------------------------------------------------------------------------------------------------------------------+

 

 

 

 

 

 

 


 


因为你的帐号权限问题才导致此错误。。。所以你要把你访问数据库的帐号的权限改一下。。

具体格式如:grant all on mysql.* to 'root'@'localhost' identified by 'password'; 
1。mysql.* 你访问的数据库名字。

2。root' 你的用户名

3。'password' 需要修改的密码。。

 

 

最后问题解决

 

MySQL的"Access denied for user"错误是指在尝试使用指定的用户名和密码登录MySQL时出现权限拒绝的情况。解决这个问题的方法有以下几种: 1. 确保用户名和密码正确:首先要确认你输入的用户名和密码是正确的。请检查大小写是否匹配,并确保没有输入错误的字符。 2. 检查用户权限:如果用户名和密码是正确的,但仍然无法登录,那么可能是因为该用户没有足够的权限。请检查用户在MySQL中的权限设置,并确保他们有足够的权限来登录和执行所需的操作。 3. 重置用户密码:如果忘记了用户的密码,可以通过重置密码来解决。可以使用以下命令来更新用户的密码: `update mysql.user set authentication_string='new_password' where user='username';` 替换`new_password`为你想要设置的新密码,`username`为要重置密码的用户名。 4. 检查MySQL服务是否启动:如果MySQL服务未启动,那么无论你输入的用户名和密码是否正确,都无法登录。请确保MySQL服务正在运行,并且没有出现任何错误。 综上所述,如果出现"Access denied for user"错误,可以通过确认用户名和密码的正确性,检查用户权限,重置用户密码以及确保MySQL服务正常运行来解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [mysql Access denied for user ‘root’@’localhost’ (using password: YES)解决方法](https://download.csdn.net/download/weixin_38624557/12830607)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [在MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password YES) 拒绝访问问题解决](https://blog.csdn.net/bhegi_seg/article/details/126081046)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值