MacOS 无法启动 MySQL 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41995912/
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 22:10:44  来源:igfitidea点击:

MacOS Can't start MySQL Server

mysqlmacos

提问by Richard

I have MacOS Sierra. I have installed MySQL Server which has been working, however, after a reboot of the Mac Book, I cannot start the MySQL Server.

我有 MacOS Sierra。我已经安装了 MySQL 服务器,它一直在工作,但是,在重新启动 Mac Book 后,我无法启动 MySQL 服务器。

enter image description here

在此处输入图片说明

I have tried changing the port from 3306to 3307in the my.cnffile.

我试图从更改端口33063307了在my.cnf文件中。

Question

I would appreciate any help on how to start the MySQL Server, and also have it so it starts automatically on MacOS Boot up.

我将不胜感激有关如何启动 MySQL 服务器的任何帮助,并且还拥有它以便它在 MacOS 启动时自动启动。

(I am new to Mac, so apologies if this is a basic question).

(我是 Mac 新手,如果这是一个基本问题,我很抱歉)。

UPDATE

更新

Looking for error logs, I can't find anything with todays (2/2/2017) timestamp.

寻找错误日志,我找不到今天 (2/2/2017) 时间戳的任何内容。

enter image description here

在此处输入图片说明

Nothing in the datadir:

data目录中没有任何内容:

enter image description here

在此处输入图片说明

No files with "mysql" have been modified since I've tried to start the MySQL Server (2/2/2017 after 09:00).

自从我尝试启动 MySQL 服务器(2/2/2017 09:00 之后)以来,没有修改带有“mysql”的文件。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

采纳答案by FreudianSlip

After a discussion with Richard, the following solves the issue:

经过与理查德的讨论,以下解决了这个问题:

my.cnf:

我的.cnf:

[client]

port = 3306
socket = /tmp/mysql.sock


[mysqld]

port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql-5.7.17-macos10.12-x86_64/data
tmpdir = /tmp

Essentially, although we'd added the relevant stanza's to the my.cnf file, we'd still missed the section heading. Adding the [mysqld] section allowed mysql to start.

本质上,尽管我们已将相关节添加到 my.cnf 文件中,但我们仍然错过了部分标题。添加 [mysqld] 部分允许 mysql 启动。

回答by y2k-shubham

In my case, I had inadvertently transferred ownership of entire /usr/localdirectory to myself, which resulted in snatching-away of write permissionof /usr/local/mysql-5.7.20-macos10.12-x86_64/datadirectory from the daemon usercalled "_mysql".

就我而言,我无意中将整个/usr/local目录的所有权转移给了自己,这导致名为“ _mysql”的守护程序用户夺走了目录的写权限/usr/local/mysql-5.7.20-macos10.12-x86_64/data

Restoring the ownership fixed the issue.

恢复所有权解决了这个问题。

回答by Sabine

After installing Mysql 8.0.12 on MacOS High Sierra, Mysql server would not start up. I tried several suggestions like removing mysql and reinstalling it, rebooting the computer and changing file permissions, all to no avail. I finally got it to work by removing /etc/my.cnf.

在 MacOS High Sierra 上安装 Mysql 8.0.12 后,Mysql 服务器无法启动。我尝试了一些建议,例如删除 mysql 并重新安装它,重新启动计算机并更改文件权限,但都无济于事。我终于通过删除/etc/my.cnf.

回答by Ares

I suggest to use Terminal commands.

我建议使用终端命令。

Start MySQL

启动 MySQL

sudo /usr/local/mysql/support-files/mysql.server start

须藤/usr/local/mysql/support-files/mysql.server 启动

Stop MySQL

停止 MySQL

sudo /usr/local/mysql/support-files/mysql.server stop

须藤/usr/local/mysql/support-files/mysql.server 停止

Restart MySQL

重启 MySQL

sudo /usr/local/mysql/support-files/mysql.server restart

须藤/usr/local/mysql/support-files/mysql.server 重启

回答by Sairam Krish

In my case, First time, after installing Mysql, Mac needs a restart.

就我而言,第一次,安装 Mysql 后,Mac 需要重新启动。

So restarting Mac, after installation, fixed the issue for me.

所以在安装后重新启动 Mac,为我解决了这个问题。

MacOS doesn't come with a my.cnf file. Default settings will suffice the needs for basic usage. Once we need to override them, it makes sense to have a custom configurations.

MacOS 不附带 my.cnf 文件。默认设置足以满足基本使用的需要。一旦我们需要覆盖它们,就有一个自定义配置是有意义的。

回答by Akexis

My problem was that I installed MySQL a while ago with Homebrew (forgot I did) and then went the more manual route, so I think the two installs were fighting each other. I wiped my Mac of both with the help of this walkthrough: https://gist.github.com/vitorbritto/0555879fe4414d18569d

我的问题是,我不久前用 Homebrew 安装了 MySQL(我忘记了),然后走的是更手动的路线,所以我认为这两个安装是相互冲突的。在本演练的帮助下,我擦除了我的 Mac:https: //gist.github.com/vitorbritto/0555879fe4414d18569d

Note: Where it says to use subl - that's Sublime, use whatever editor you like.

注意:它说使用 subl 的地方 - 那是 Sublime,使用您喜欢的任何编辑器。

I was able to get things to work with a fresh install after that.

在那之后,我能够通过全新安装使事情正常工作。

回答by Gabriel Lupu

My problem was that due to an incorrect restart of my machine, a database was corrupted. According to their docs doing a forced InnoDB Recoverydid the trick:

我的问题是由于我的机器不正确重新启动,数据库已损坏。根据他们的文档,强制 InnoDB 恢复成功了:

/etc/my.cnf

innodb_force_recovery = 2

回答by Hyman BeNimble

In my case, ownership of the msyql directory had somehow changed to admin:admin. I use ares suggestion to run mysqld from the terminal:

就我而言,msyql 目录的所有权以某种方式更改为 admin:admin。我使用 ares 建议从终端运行 mysqld:

sudo /usr/local/mysql/support-files/mysql.server start

Which showed a permissions error writing to a msyql file.

其中显示写入 msyql 文件的权限错误。

I fixed with this command:

我用这个命令修复:

sudo chown -R _mysql:wheel /usr/local/mysql/data

from this post:

从这篇文章:

What user should own /usr/local/mysql on Mac?

什么用户应该在 Mac 上拥有 /usr/local/mysql?