Home > Database > Mysql Tutorial > body text

使用“忽略授权表”参数登录多实例数据库用于多实例数据库忘

WBOY
Release: 2016-06-07 14:52:48
Original
968 people have browsed it

昨天上午,在视频“L10-008-lamp环境之MySQL多实例安装配置指南”马上就要结束的时候,再次遇到问题。 前天晚上,根据视频讲解在清理多余MySQL数据库账号后,就直接退出数据库并关机了(没有在清理账号后,退出数据库并重新登录数据库——其实,也没有必要做

  昨天上午,在视频“L10-008-lamp环境之MySQL多实例安装配置指南”马上就要结束的时候,再次遇到问题。

  前天晚上,根据视频讲解在清理多余MySQL数据库账号后,就直接退出数据库并关机了(没有在清理账号后,退出数据库并重新登录数据库——其实,也没有必要做这样的测试)。昨天早上打开虚拟机,想着完成视频的最后一小部分。没想到,在使用密码登录3306实例的时候,无论如何也登录不进去了。

[root@Web 3306]# mysql -uroot -p -S /data/3306/mysql.sock
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@Web 3306]# mysql -uroot -p'oldboy3306' -S /data/3306/mysql.sock
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Copy after login

  在百度搜索这个报错信息的相关内容,还是把我引向歧途。通过错误日志,也没有找到正确的解决办法。

  很多信息都是重置密码,这个办法在oldboy的“L10-002-MySQL常用基本命令-查看帮助及修改密码02”视频里也讲过。但是,各方面的资料都是针对单实例情况的重置密码。

  无计可施,只好把这个问题发到QQ群里。上午还没有消息,下午我尝试再次请教QQ群,总算有同学回复我1条多实例重置密码的命令。这样,我就可以使用重置后的密码,尝试登录数据库了。

  但是,更换密码之后,登录报错的问题还是没有解决。看来,这次的问题和密码无关。

  这里,先把多实例重置密码的操作整理出来,供日后需要的时候查阅。


  忘记登录多实例数据库的密码,需要使用“忽略授权表”的参数登录数据库。但是,命令与单实例使用的命令略有不同。

[root@Web ~]# netstat -lnt|grep 330
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN
[root@Web ~]# killall mysqld
[root@Web ~]# killall mysqld
[root@Web ~]# killall mysqld
mysqld: no process killed
[root@Web ~]# mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-table &
[1] 6015
140607 15:11:58 mysqld_safe Logging to '/data/3306/mysql_oldboy3306.err'.
140607 15:11:59 mysqld_safe Starting mysqld daemon with databases from /data/3306/data

[root@Web ~]# netstat -lnt|grep 330
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN
Copy after login

  登录多实例数据库不需要密码验证:

[root@Web ~]# mysql -uroot -S /data/3306/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| oldboy3306         |
| test               |
+--------------------+
4 rows in set (0.03 sec)

mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | Web       | *007FFCA4271EE782CBEE4DB65344C906C10915BB |
| root | 127.0.0.1 | *007FFCA4271EE782CBEE4DB65344C906C10915BB |
+------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)

mysql> quit
Bye
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!