MySQL:无法访问根帐户 [英] MySQL: can't access root account

查看:107
本文介绍了MySQL:无法访问根帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地Windows机器上运行MySQL 5.x,并且使用MySQL管理员,无法连接到使用root帐户创建的数据库.我得到的错误是:

I'm running MySQL 5.x on my local Windows box and, using MySQL administrator, I can't connect to the databases I created using the root account. The error I get is:

MySQL错误号1045访问被拒绝 对于用户'root'@'localhost'(使用 密码:是)

MySQL Error number 1045 Access denied for user 'root'@'localhost' (using password: YES)

我不记得更改根帐户的凭据,但是我知道我试图通过添加IP来使LAN上的其他计算机访问数据库.我为其中一个IP所做的一件事是指定对帐户'root'而不是root的访问权限,即,我用单引号char包围了root.全部使用MySQL管理员.这可能是我无法使用root登录的原因吗?

I can't recall changing root account credentials, but I know I tried to give other computers on the LAN access to the db by adding their IPs. One thing I did for one of the IPs was to specify access to the account 'root' instead of root, i.e. I surrounded root with single quotation chars. All using MySQL administrator. Could this be the reason why i can't login using root?

还有没有办法创建新帐户或重置根帐户?如前所述,我可以完全访问我的盒子.

Also, is there a way to create a new or reset the root account? As previously mentioned, I have full access to my box.

查看这些问题

推荐答案

您可以使用init文件.在如何重设根密码上查看MySQL官方文档(包括对其他解决方案的评论).

You can use the init files. Check the MySQL official documentation on How to Reset the Root Password (including comments for alternative solutions).

因此,基本上使用初始化文件,您可以将修复访问所需的任何SQL查询(例如GRANDCREATEFLUSH PRIVILEGES等)添加到初始化文件(任何文件)中.

So basically using init files, you can add any SQL queries that you need for fixing your access (such as GRAND, CREATE, FLUSH PRIVILEGES, etc.) into init file (any file).

这是我恢复根帐户的示例:

Here is my example of recovering root account:

echo "CREATE USER 'root'@'localhost' IDENTIFIED BY 'root';" > your_init_file.sql
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;" >> your_init_file.sql 
echo "FLUSH PRIVILEGES;" >> your_init_file.sql

创建文件后,可以运行:

and after you've created your file, you can run:

killall mysqld
mysqld_safe --init-file=$PWD/your_init_file.sql

然后检查是否可行,请按 Ctrl + Z 并键入:bg将进程从前台运行到后台,然后通过以下方式验证您的访问权限:

then to check if this worked, press Ctrl+Z and type: bg to run the process from the foreground into the background, then verify your access by:

mysql -u root -proot
mysql> show grants;
+-------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' |

另请参阅:

  • No Password – No Problem at Everything MySQL
  • Bug #28331: Unclear error message when CREATE USER fails due to duplicate key

这篇关于MySQL:无法访问根帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆