码迷,mamicode.com
首页 > 数据库 > 详细

登录多实例MySQL失败,修改密码临时解决,原因不明

时间:2014-07-28 00:38:50      阅读:403      评论:0      收藏:0      [点我收藏+]

标签:多实例 mysql 登录失败 修改密码 刷新权限

  昨天学习第11课“主从同步”的视频(L11-11-MySQL主从同步手把手实战操作详解w),再次遇到问题。

[root@Web ~]# mysql -uroot -p‘oldboy3307‘ -S /data/3307/mysql.sock
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

  上个月初学习安装多实例的时候,也遇到过这个报错。查看当时的日记,发现自己整理的文档也有很多问题。2个月之后再看,发现虽然想记录的很详细,但思路还是有些乱。

  根据日记里的记录:使用如下的命令启动数据库服务。

[root@Web ~]# mysqld_safe --defaults-file=/data/3307/my.cnf --skip-grant-table &
[1] 4959
140726 19:04:23 mysqld_safe Logging to ‘/data/3307/mysql_oldboy3307.err‘.
140726 19:04:23 mysqld_safe Starting mysqld daemon with databases from /data/3307/data


  登录数据库后,使用授权语句竟然报错。

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "111";
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

  至今也不明白这个报错是什么意思,百度上只是说可以通过刷新权限“flush privileges;”解决。

  尝试正常启动数据库:

[root@Web ~]# /data/3307/mysql start
Starting MySQL...

  使用另外的命令登录数据库,也是报错。

[root@Web ~]# mysql -uroot -p -S /data/3307/mysql.sock -h 127.0.0.1
Enter password: 
ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘127.0.0.1‘ (111)

  最后决定,还是直接在数据库里把root密码改了再说。

[root@Web ~]# mysqld_safe --defaults-file=/data/3307/my.cnf --skip-grant-table &
[1] 5535
140726 19:15:56 mysqld_safe Logging to ‘/data/3307/mysql_oldboy3307.err‘.
140726 19:15:56 mysqld_safe Starting mysqld daemon with databases from /data/3307/data

[root@Web ~]# netstat -lnt|grep 330
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN
[root@Web ~]# mysql -uroot -S /data/3307/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.62-log 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,password from mysql.user;
+-------+-------------+-------------------------------------------+
| user  | host        | password                                  |
+-------+-------------+-------------------------------------------+
| root  | %           | *007FFCA4271EE782CBEE4DB65344C906C10915BB |
| root  | localhost   | *007FFCA4271EE782CBEE4DB65344C906C10915BB |
| root  | 127.0.0.1   | *007FFCA4271EE782CBEE4DB65344C906C10915BB |
| user2 | localhost   | *12A20BE57AF67CBF230D55FD33FBAF5230CFDBC4 |
| rep   | 192.168.1.% | *FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515 |
+-------+-------------+-------------------------------------------+
5 rows in set (0.00 sec)

mysql> update mysql.user set password=PASSWORD(‘123456‘) where user=‘root‘;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> quit
Bye

  看到没有,修改密码之后我竟然没有刷新权限。结果,登录的时候就容易出现问题。当然,不是一定会出现问题。

  我这里修改密码为“123456”之后,登录数据库是没有问题的。但是,在数据库里再次把密码修改为“oldboy3307”,退出再次登录数据库,就又报错了。

  把数据库的root密码再次修改为“123456”之后,再来一遍:

[root@Web ~]# mysql -uroot -p‘123456‘ -S /data/3307/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.62-log 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> update mysql.user set password=PASSWORD(‘oldboy3307‘) where user=‘root‘;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

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

mysql> quit
Bye
[root@Web ~]# mysql -uroot -p‘oldboy3307‘ -S /data/3307/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.62-log 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> quit
Bye

  这次,最后的问题,似乎是没有刷新权限的原因。但是,看起来这又好像只是表象。

  刚才登录数据库还一切正常,为什么退出之后就不能登录了呢?为什么修改密码之后,就又可以登录了呢?为什么有时候在修改密码之后,即使没有刷新权限也可以登录数据库,有时候又不能登录呢?

  保留这些问题,慢慢研究。

  整理出这个文档,这是我目前唯一能做的了。

本文出自 “dark-matter” 博客,请务必保留此出处http://gagarin.blog.51cto.com/1056957/1530937

登录多实例MySQL失败,修改密码临时解决,原因不明,布布扣,bubuko.com

登录多实例MySQL失败,修改密码临时解决,原因不明

标签:多实例 mysql 登录失败 修改密码 刷新权限

原文地址:http://gagarin.blog.51cto.com/1056957/1530937

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!