MySQL mysql5 - 由于“root”无法创建数据库或执行任何操作(访问被拒绝)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10130296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:56:07  来源:igfitidea点击:

mysql5 - As 'root' can't create database or do anything (Access denied)

mysqlmacososx-lionmacportsmysql5

提问by John Jorgensen

I'm on Mac OS X Lion and just installed mysql5 using MacPorts.

我在 Mac OS X Lion 上,刚刚使用 MacPorts 安装了 mysql5。

Then I successfully ran:

然后我成功运行:

sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql

I'm able to start the server and connect as 'root' fine, but I can't create any databases.

我可以启动服务器并以“root”身份连接,但我无法创建任何数据库。

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'

I've done a lot of Googling trying to figure this out, and it appears that the problem might have to do with file system permissions for /opt/local/var/db/mysql5, but I've tried changing these to no avail:

我已经做了很多谷歌搜索试图解决这个问题,似乎问题可能与 /opt/local/var/db/mysql5 的文件系统权限有关,但我尝试更改这些无济于事:

$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5

I've experimented with the owner being '_mysql', 'mysql', and 'root:wheel', but none of them have made a difference.

我已经尝试过将所有者设为 '_mysql'、'mysql' 和 'root:wheel',但它们都没有产生任何影响。

回答by John Jorgensen

FIXED -- mysql created my 'root' account with no privileges (I'm a mysql newb).

已修复 - mysql 创建了我的“root”帐户而没有任何权限(我是 mysql 新手)。

I solved by starting mysql with

我通过启动 mysql 解决了

--skip-grant-tables

Then launching with:

然后启动:

mysql5

And running:

并运行:

mysql> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> GRANT ALL ON *.* TO 'root'@'localhost';

Hope this helps someone!

希望这可以帮助某人!

回答by NM Pennypacker

I know this is an old question, but I ran into this issue on a new Macbook running Catalina. The project I'm working on requires me to run an older version of MySQL (5.7), so I installed it via Homebrew and ran into the same issue; unable to do pretty much everything, even as rootuser.

我知道这是一个老问题,但我在运行 Catalina 的新 Macbook 上遇到了这个问题。我正在做的项目要求我运行旧版本的 MySQL (5.7),所以我通过 Homebrew 安装它并遇到了同样的问题;即使作为root用户,也几乎无法做任何事情。

Rebooting my machine fixed the problem, and I've waited my whole Stack Overflow career to post this as an answer, so here it is:

重新启动我的机器解决了这个问题,我一直在等待我的整个 Stack Overflow 职业生涯来发布这个作为答案,所以这里是:

Turn it off and turn it back on again

将其关闭并重新打开