无法诊断我的 MySQL root 用户问题

发布于 2024-08-04 22:26:32 字数 634 浏览 3 评论 0原文

我的 MySQL 设置中的 MySQL root 用户有问题,我一生都无法解决它。看来我以某种方式搞乱了 root 用户,现在我对数据库的访问非常不稳定。

作为参考,我在 OS X 上使用 MAMP 来提供 MySQL 服务器。我不确定这有多重要 - 我猜想无论我做了什么都需要命令行修复来解决它。

我可以像往常一样使用 MAMP 启动 MySQL,并使用我为 PHP 应用程序创建的“标准”用户访问数据库。然而,我在 MySQL GUI 客户端和 phpMyAdmin 中使用的 root 用户只能访问“information_schema”数据库,以及我手动创建的两个数据库,并且可能(并且错误地)将权限完全开放。 root 用户无法访问我的 15 个左右的其他数据库。当我加载 phpMyAdmin 时,主屏幕显示:“创建新数据库:无权限”。

我确实在某个阶段使用 MAMP 对话框更改了 root 用户的密码。但我不记得我是否做了其他可能导致此问题的事情。我再次尝试更改密码,问题似乎没有变化。

我还尝试使用命令行重置 root 密码,包括使用 --skip-grant-tables 手动启动 mysql,然后刷新 privs,但同样,似乎没有什么可以解决问题。

我的想法已经结束,非常感谢这里一位专家提供的一些逐步建议和诊断!

非常感谢您的帮助。

I have a problem with the MySQL root user in My MySQL setup, and I just can't for the life of me work out how to fix it. It seems that I have somehow messed up the root user, and my access to databases is now very erratic.

For reference, I'm using MAMP on OS X to provide the MySQL server. I'm not sure how much that matters though - I'd guess that whatever I've done will require a command-line fix to solve it.

I can start MySQL using MAMP as usual, and access databases using the 'standard' users I have created for my PHP apps. However, the root user, which I use in my MySQL GUI client, and also in phpMyAdmin, can only access the "information_schema" database, as well as two I have created manually, and presumably (and mistakenly) left permissions wide open for. My 15 or so other databases cannot be accessed my the root user. When I load up phpMyAdmin, the home screen says: "Create new database: No Privileges".

I certainly did at some stage change my root user's password using the MAMP dialog. But I don't remember if I did anything else which might have caused this problem. I've tried changing the password again, and there seems to be no change in the issue.

I've also tried resetting root password using the command line, including starting mysql manually with --skip-grant-tables then flushing privs, but again, nothing seems to fix the issue.

I've come to the end of my ideas, and would very much appreciate some step-by-step advice and diagnosis from one of the experts here!

Many thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不回头走下去 2024-08-11 22:26:32

我遇到了同样的问题:只有一个用户帐户可以通过管理控制台或查询浏览器访问 mysql 数据库。当我使用skip-grant-tables时,突然所有帐户都可以登录,包括root。

我看到它早在 2006 年就已经是一个 bug,但最后的条目在那里不是在skip-grant-tables模式下可以执行的命令,所以我仍然没有解决这个问题。

什么对我有帮助
此答案与 Ben Bakelaar 在上述链接中描述的答案类似。当您的 my.ini 禁用名称解析标志 (skip-name-resolve) 时,就会出现问题。这会破坏 mysql 解析“localhost”的能力,并且 mysql.user 表只有 localhost / root 的条目。

将 mysql.user 表的 localhost 条目更新为 127.0.0.1,即使启用了跳过名称解析功能,您也可以登录到本地控制台。

I had the same issue: only one user account worked to access the mysql databases via the administration console or the query browser. When I used the skip-grant-tables suddenly all accounts could log in, including root.

I saw it as a bug as far back as 2006, but the final entry there isn't a command that can be executed when in skip-grant-tables mode, so I still hadn't solved the issue.

What helped me
This answer is similar to one described by Ben Bakelaar in the above link. The problem comes when your my.ini has the name resolution flag disabled (skip-name-resolve). This kills mysql's ability to resolve 'localhost' and the mysql.user table only has an entry for localhost / root.

Update your mysql.user table's localhost entry to be 127.0.0.1 instead, and you can log in to the local consoles even with the skip-name-resolve feature enabled.

め可乐爱微笑 2024-08-11 22:26:32

尝试使用 --skip-grant-tables 启动服务器,然后检查 mysql 数据库中的权限表:

select * from user where User='root';
select * from tables_priv where User='root';
select * from db where User='root';

您也可以尝试:

show grants for root@localhost;
show grants for root@'%';
show grants for root@'hostname';

一旦进入,您可以执行以下操作来尝试授予 root 完全权限:

grant all privileges on *.* to root@localhost identified by 'password' with grant option;

Try starting the server with --skip-grant-tables and then checking the privilege tables in the mysql database:

select * from user where User='root';
select * from tables_priv where User='root';
select * from db where User='root';

You could also try:

show grants for root@localhost;
show grants for root@'%';
show grants for root@'hostname';

Once in you could do this to attempt to give root full privileges:

grant all privileges on *.* to root@localhost identified by 'password' with grant option;
骑趴 2024-08-11 22:26:32

您的评论显示您当前的 root 权限(不带 --skip-grant-tables)。如果您没有任何“root”@“%”条目,这很好,默认情况下您没有该条目,您可以将其视为一种安全措施。

看起来您已经搞乱了您的 'root'@'localhost' 权限。 GRANT ALL PRIVILEGES ON . 很奇怪。通常,您有类似 GRANT ALL PRIVILEGES ON *.*GRANT ALL PRIVILEGES ON myDatabase.myTable 的内容。您的 GRANT 未指定要授予权限的数据库和/或表。我不知道你的客户是如何制作它的。我无法使用 mysql 命令行客户端重现它(尝试过空字符串、空格、任何类型的引号...),mysql 拒绝 GRANT 语句(当然,这是正确的行为)。看起来 MAMP 正在做一些非常奇怪的事情。由于我无法像您一样重现 GRANT ,我无法说出 mysql 如何解释它,但我猜它已在全局级别将权限设置为 'N'

要修复它,您需要具有适当权限的用户。通常,您有一个用户 'root'@'localhost''root'@'your-hostname'。如果幸运的话,'root'@'your-hostname' 仍然没问题。公平地说,mysql 连接的工作方式如下:如果连接到 localhost,则以 'root'@'localhost' 身份连接(不确定 127.0.0.1) code>,我猜它也是 'root'@'localhost')。如果您连接到 your-hostname,则将以 'root'@'your-hostname' 身份进行连接。如果该用户的权限仍然可以,您可以更新 'root'@'localhost' 的权限,然后就完成了。

在您的评论中,您说您无法通过 127.0.0.1 连接,因为套接字位于不寻常的位置。我猜你误解了这个错误。 IIRC 如果您连接到 'localhost',则通过套接字进行连接,但如果您连接到 127.0.0.1your-hostname,则通过 TCP/IP 进行连接。如果 mysql 尝试通过套接字连接并且找不到套接字(因为您没有指定正确的位置),则错误消息会提到 mysql 尝试在何处查找套接字。您的错误消息没有。我猜你的错误是网络错误。也许您已经使用 --skip-networking 选项启动了 mysql-server,或者您的配置指定了不正确的绑定地址。您需要先解决这个问题,否则您将无法以 'root'@'your-hostname' 身份进行连接。

Your comment shows your current root privileges (without --skip-grant-tables). It's fine that you do not have any entry for 'root'@'%', you do not have that by default and you can consider it a security measure.

It looks like you've messed up your 'root'@'localhost' privileges. GRANT ALL PRIVILEGES ON . is weird. Usually, you have something like GRANT ALL PRIVILEGES ON *.* or GRANT ALL PRIVILEGES ON myDatabase.myTable. Your GRANT does not specify the databases and/or tables to grant the privileges for. I have no idea how your client managed to produce it. I cannot reproduce it with the mysql commandline client (tried empty strings, whitespace, any kind of quotes...), mysql refuses the GRANT statement (which, of course, is the correct behaviour). Looks like MAMP is doing something really strange. Since I cannot reproduce a GRANT like yours, I cannot say how mysql interprets that, but I guess it has set the privileges to 'N' on the global level.

To fix it, you need a user with appropiate privileges. Usually, you have a user 'root'@'localhost' and a 'root'@'your-hostname'. If you're lucky, 'root'@'your-hostname' is still fine. Afair, mysql connections work as follows: If you connect to localhost, you connect as 'root'@'localhost' (not sure about 127.0.0.1, I guess it is also 'root'@'localhost'). If you connect to your-hostname, you connect as 'root'@'your-hostname'. If this user's privileges are still ok, you can update the privileges for 'root'@'localhost' and you are done.

In your comment, you say you cannot connect via 127.0.0.1 since the socket is in an unusual place. I guess you misinterpret the error. IIRC you connect via socket if you connect to 'localhost', but via TCP/IP if you connect to 127.0.0.1 or your-hostname. If mysql tries to connect via socket and cannot find the socket (because you did not specify the correct location), the error message mentions where mysql tried to find the socket. Your error message does not. I guess your error is a networking error. Maybe you've started the mysql-server with the --skip-networking option, or your configuration specifies an incorrect bind-address. You need to fix that first, otherwise you can't connect as 'root'@'your-hostname'.

陌生 2024-08-11 22:26:32

那是因为 MAMP 和命令行 mysql(以及除 MAMP 之外的 mysql 一切)是不同的。

MAMP 有自己内置的 mysql,您无法通过命令行访问它,只能通过 phpmyadmin 中的构建来访问它。

这是我的经验,我有 MAMP 并使用其他 mysql 来处理 ruby​​ on Rails 和其他东西。

Thats because MAMP and the command line mysql (and the mysql everything except MAMP) are different.

MAMP has its own built in mysql and you can't get to it via the command line, only the build in phpmyadmin.

this has been my experience, I have MAMP and use the other mysql for ruby on rails and other stuff.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文