免费注册 查看新帖 |

Chinaunix

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

多实例删除数据库中的空账号后,为什么输入密码再也登录不进数据库了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-06-07 12:04 |只看该作者 |倒序浏览
删除多余空账号后,退出数据库后就再也登录不进去了。
  1. [root@Web 3306]# mysql -uroot -p -S /data/3306/mysql.sock
  2. Enter password:
  3. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
复制代码
密码输入是正确的。
  1. [root@Web 3306]# mysql -uroot -p'oldboy3306' -S /data/3306/mysql.sock
  2. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
复制代码
但是,另一个实例就没有问题。
  1. [root@Web 3306]# /data/3307/mysql start
  2. Starting MySQL...
  3. [root@Web 3306]# netstat -lnt|grep 33                                
  4. tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      
  5. tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      
  6. [root@Web 3306]# mysql -uroot -p'oldboy3307' -S /data/3307/mysql.sock  
  7. Welcome to the MySQL monitor.  Commands end with ; or \g.
  8. Your MySQL connection id is 1
  9. Server version: 5.1.62-log Source distribution

  10. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

  11. Oracle is a registered trademark of Oracle Corporation and/or its
  12. affiliates. Other names may be trademarks of their respective
  13. owners.

  14. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
复制代码
单实例视频里提到的“忽略授权表”命令好像只能对单实例的数据库有作用。我用在这个多实例上,根本没有效果。
  网上很资料也是关于“mysqld_safe --skip-grant-tables &”,我感觉,对我没什么帮助。

  这到底是为什么呢?

论坛徽章:
2
酉鸡
日期:2014-02-19 09:11:08摩羯座
日期:2014-05-23 10:16:16
2 [报告]
发表于 2014-06-09 09:58 |只看该作者
那就是被你删掉了,把user表贴出来看看

论坛徽章:
0
3 [报告]
发表于 2014-06-09 18:25 |只看该作者
回复 2# tiankafeiwu


    谢谢,问题已经解决。

论坛徽章:
0
4 [报告]
发表于 2014-06-09 18:28 |只看该作者
  增加参数:“-h 127.0.0.1”,输入密码成功登录数据库。
  1. [root@Web ~]# mysql -uroot -p -S /data/3306/mysql.sock -h 127.0.0.1
  2. Enter password:
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.1.62-log Source distribution

  6. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.

  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  11. mysql> select user,host,password from mysql.user;
  12. +------+-----------+-------------------------------------------+
  13. | user | host      | password                                  |
  14. +------+-----------+-------------------------------------------+
  15. | root | Web       | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
  16. | root | 127.0.0.1 | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
  17. +------+-----------+-------------------------------------------+
  18. 2 rows in set (0.00 sec)
复制代码
  为MySQL添加root远程登录权限(3306实例的登录密码是“111”):

  1. mysql> use mysql;
  2. Database changed
  3. mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "111";
  4. Query OK, 0 rows affected (0.00 sec)

  5. mysql> flush privileges;
  6. Query OK, 0 rows affected (0.00 sec)

  7. mysql> quit
  8. Bye
  9. [root@Web ~]# mysql -uroot -p -S /data/3306/mysql.sock
  10. Enter password:
  11. Welcome to the MySQL monitor.  Commands end with ; or \g.
  12. Your MySQL connection id is 9
  13. Server version: 5.1.62-log Source distribution

  14. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

  15. Oracle is a registered trademark of Oracle Corporation and/or its
  16. affiliates. Other names may be trademarks of their respective
  17. owners.

  18. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  19. mysql> select user,host,password from mysql.user;
  20. +------+-----------+-------------------------------------------+
  21. | user | host      | password                                  |
  22. +------+-----------+-------------------------------------------+
  23. | root | %         | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
  24. | root | localhost | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
  25. | root | 127.0.0.1 | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
  26. +------+-----------+-------------------------------------------+
  27. 3 rows in set (0.00 sec)

  28. mysql> quit
  29. Bye
复制代码


  解决问题后,我就怀疑是清理多余账号时,出现误删除,导致登录数据库报错,原因可能是root失去在本地登录数据库的权限。

论坛徽章:
0
5 [报告]
发表于 2014-06-10 01:43 |只看该作者
你的user表里没有root@localhost的账号,当然无法使用socket的方式在机器本地登陆了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP