免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 20186 | 回复: 8
打印 上一主题 下一主题

【讨论中】关于Access denied for user root@localhost (using password: YES) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-08-20 09:09 |只看该作者 |倒序浏览
本帖最后由 cenalulu 于 2012-08-20 09:47 编辑

安装应用程序,连接MySQL时,提示Access denied for user root@localhost (using password: YES)。

试了很多方法都没解决,后来的解决方法很奇怪,谁能解释下。

首先,应用程序和数据库同一台机器;数据库密码没问题;局域网其他机器上的数据库客户端访问数据库没问题;主机HOST设置没问题。

应用程序配置用127.0.0.1连接本机数据库,一直提示上面的错误。之后把地址设为本机IP,数据库连接就正常了。

论坛徽章:
0
2 [报告]
发表于 2012-08-20 09:26 |只看该作者
select * from mysql.user  看表中的Host字段,你就会明白。

论坛徽章:
0
3 [报告]
发表于 2012-08-20 09:37 |只看该作者
回复 2# 龙雪刚


    root设过host为 “%”   

难道一定要为root设一个127.0.0.1  ?

论坛徽章:
0
4 [报告]
发表于 2012-08-20 13:33 |只看该作者
貌似mysql5.5的%不包含localhost

论坛徽章:
1
2015亚冠之本尤德科
日期:2015-06-05 17:25:48
5 [报告]
发表于 2012-08-20 15:32 |只看该作者
你可以创建一个用户,赋予相关的权限试试看

grant select,insert,update,delete on *.* to 'zsd' @'localhost' identified by 'zsd';

论坛徽章:
0
6 [报告]
发表于 2012-08-20 19:41 |只看该作者
rucypli 发表于 2012-08-20 13:33
貌似mysql5.5的%不包含localhost


包含的,%代表任意主机

论坛徽章:
0
7 [报告]
发表于 2012-08-20 22:58 |只看该作者
o0o520 发表于 2012-08-20 19:41
包含的,%代表任意主机

5.5不包含

论坛徽章:
0
8 [报告]
发表于 2012-08-22 10:15 |只看该作者
rucypli 发表于 2012-08-20 22:58
5.5不包含


刚在5.5下测了一下,没问题的

# /opt/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.5.20 Source distribution

Copyright (c) 2000, 2011, 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> select user,host from mysql.user\G
*************************** 1. row ***************************
user: root
host: %
1 row in set (0.00 sec)

论坛徽章:
2
2015年迎新春徽章
日期:2015-03-04 09:55:28IT运维版块每日发帖之星
日期:2016-07-29 06:20:00
9 [报告]
发表于 2012-08-22 12:06 |只看该作者
本帖最后由 ning_lianjie 于 2012-08-22 12:11 编辑

回复 6# o0o520
刚才测试一下,确实是包含的.
注意mysql.sock和%
  1. 12:10:10 localhost:mysql.sock (none)>show grants;   
  2. +--------------------------------------------------------------------------------------------------------------------------------+
  3. | Grants for root@%                                                                                                              |
  4. +--------------------------------------------------------------------------------------------------------------------------------+
  5. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*40D06554F8934B348A298FBB3C44A5901AD74369' WITH GRANT OPTION |
  6. +--------------------------------------------------------------------------------------------------------------------------------+
  7. 1 row in set (0.00 sec)
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP