在 Mavericks 上使用 Homebrew 安装 MySQL 时出现问题

Posted

技术标签:

【中文标题】在 Mavericks 上使用 Homebrew 安装 MySQL 时出现问题【英文标题】:Problems installing MySQL with Homebrew on Mavericks 【发布时间】:2014-03-26 17:37:32 【问题描述】:

我在 Mavericks 上使用 Homebrew 安装 mysql 时遇到了严重的问题。我知道有一个类似名称的主题,但我已经尝试了那里写的所有内容以及至少 20 个站点,但没有成功尝试使其工作。我尝试根据不同的教程安装步骤,但没有任何效果。

我是这样去的:

brew update
brew doctor
brew upgrade

brew install mysql

Brew 将其安装在 /usr/local/Cellar/mysql/5.6.16 ...

我尝试按照 Brew 所说的进行连接:mysql -uroot

我创建 LaunchAgents 目录,将自制 plist 文件链接到它并启动控件:

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

之后我尝试使用 sudo mysql.server start 启动 mysql 服务器,但出现套接字错误

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

我尝试使用mysqld_safe & 启动服务器,但得到以下输出:

[1] 69187
Davids-MacBook-Air-5:~ davidsupan$ 140224 14:39:16 mysqld_safe Logging to     '/usr/local/var/mysql/Davids-MacBook-Air-5.local.err'.
touch: /usr/local/var/mysql/Davids-MacBook-Air-5.local.err: Permission denied
140224 14:39:16 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
/usr/local/bin/mysqld_safe: line 129: /usr/local/var/mysql/Davids-MacBook-Air-5.local.err: Permission denied
/usr/local/bin/mysqld_safe: line 166: /usr/local/var/mysql/Davids-MacBook-Air-5.local.err: Permission denied
140224 14:39:16 mysqld_safe mysqld from pid file /usr/local/var/mysql/Davids-MacBook-Air-5.local.pid ended
/usr/local/bin/mysqld_safe: line 129: /usr/local/var/mysql/Davids-MacBook-Air-5.local.err: Permission denied

以下命令似乎可以解决问题 sudo chmod -R 755 /usr/local/var/mysql rm -Rf /usr/local/var/mysql/Davids-MacBook-Air-5.local.err

mysql.server restart

mysql服务器成功启动

Shutting down MySQL
.. SUCCESS! 
Starting MySQL
. SUCCESS! 

其他时候,无论我做什么,我都会不断收到以下错误

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

一些页面建议这样做

unset TMPDIR
mysql_install_db --verbose --user='whoami' \\
--basedir="$(brew --prefix mysql)" \\
--datadir=/usr/local/var/mysql --tmpdir=/tmp

但我没有成功解决这个问题。

任何帮助将不胜感激。我希望我对问题的描述足够详细。如果没有,我很乐意提供更多信息。

编辑:我尝试 mysqld restart 得到更多错误:

2014-02-25 12:35:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-02-25 12:35:54 34599 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2014-02-25 12:35:54 34599 [Note] Plugin 'FEDERATED' is disabled.
2014-02-25 12:35:54 34599 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-02-25 12:35:54 34599 [Note] InnoDB: The InnoDB memory heap is disabled
2014-02-25 12:35:54 34599 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-02-25 12:35:54 34599 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-02-25 12:35:54 34599 [Note] InnoDB: Using CPU crc32 instructions
2014-02-25 12:35:54 34599 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-02-25 12:35:54 34599 [Note] InnoDB: Completed initialization of buffer pool
2014-02-25 12:35:54 34599 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
2014-02-25 12:35:54 34599 [ERROR] InnoDB: The system tablespace must be writable!
2014-02-25 12:35:54 34599 [ERROR] Plugin 'InnoDB' init function returned error.
2014-02-25 12:35:54 34599 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
mysqld: Too many arguments (first extra is 'restart').
Use --verbose --help to get a list of available options
2014-02-25 12:35:54 34599 [ERROR] Aborting

2014-02-25 12:35:54 34599 [Note] Binlog end
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'partition'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_METRICS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_CMPMEM'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_CMP'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_LOCKS'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'INNODB_TRX'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'BLACKHOLE'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'ARCHIVE'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'MRG_MYISAM'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'MyISAM'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'MEMORY'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'CSV'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'sha256_password'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'mysql_old_password'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'mysql_native_password'
2014-02-25 12:35:54 34599 [Note] Shutting down plugin 'binlog'
2014-02-25 12:35:54 34599 [Note] mysqld: Shutdown complete

【问题讨论】:

你能找到你的 my.cnf 文件吗? 不,我在任何文件夹中都找不到 my.cnf 文件。 你试过通过 brew 卸载 mysql 吗? ***.com/questions/4359131/… 如果是这样,您也许可以使用 brew 重新安装它 我试过多次卸载它。它总是会出现同样的错误。 我只是能够通过从我的 /etc 目录中删除一个无关的 my.cnf 文件来解决我的问题。见***.com/questions/2482234/… 【参考方案1】:

我们昨天遇到了同样的问题。 我的错误是执行

sudo launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

第一次,但forgot 卸载它。几个线索:

    一个进程mysqld_saferoot下运行 一个进程mysql_mysql 下运行 updown 一次又一次。 错误文件/usr/local/var/mysql/*.err的所有者是_mysql 运行sudo launchctl list | grep mysql时,存在mysql服务

解决方法很简单:

sudo launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

根本原因是,homebrew 的 mysql 不假定在root 下运行,至少看起来是这样。

也许它和你的问题不一样,但我希望它会有所帮助。

【讨论】:

【参考方案2】:

这主要看起来像一个权限问题。这两行很关键:

2014-02-25 12:35:54 34599 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
2014-02-25 12:35:54 34599 [ERROR] InnoDB: The system tablespace must be writable!

我可以看到您对 mysql 文件设置了权限,但您可能也应该检查所有权。使用 homebrew 通常可以安全地使用 sudo chown -R david:staff /usr/localsudo chmod u+rwX /usr/local(比 0755 权限更好的选择),并且 homebrew 下的 mysql 应该像你一样运行。

在安装时,我建议您考虑使用 MySQL 的 Percona server 版本,该版本在自制软件中也可作为 percona-server 使用。您也可以考虑 MariaDB - 它们都是普通 MySQL 的直接替代品,并且具有一些优势。

【讨论】:

以上是关于在 Mavericks 上使用 Homebrew 安装 MySQL 时出现问题的主要内容,如果未能解决你的问题,请参考以下文章

如何在Mac OS X上安装 Ruby运行环境

OpenGL 不使用 GLFW 和 GLLoadGen 在 Mavericks 上绘图

在 Mavericks 上安装 libtiff

无法在安装了命令行工具的 Mavericks 上使用 xcodebuild

如何使用 Xcode 5.0.2 在 Mavericks 上签署应用程序?

Android Studio 无法在 Mac OSX (Mavericks) 上加载 JVM