由于 MySQL 错误而无法运行迁移
几天来我一直在尝试在 OS X 上设置我的开发环境,但我在 mysql 方面遇到了很多麻烦。我已经通过 mysql 网站上提供的 dmg 文件安装了 mysql。这解决了我遇到的大部分麻烦。
我当前的问题是,当我运行“rake db:migrate”时,出现以下错误:
耙子中止!
Mysql:Class 的未定义方法“init”
我在某处读到,在 Gemfile 中使用 gem 'mysql2' 并使用 mysql2 作为数据库适配器可能会解决问题。我尝试这样做,但没有成功。需要注意的一件事是 mysql 不在我的 PATH 变量中的任何位置,因此在终端中输入“mysql”会将我带到 /var/_mysql,这有点奇怪。
我需要将“/usr/local/mysql/bin”添加到我的路径变量中吗?如果是这样,我该如何在 OS X 中执行此操作?
谢谢。
编辑:我将 /usr/local/mysql/bin 添加到我的路径中,仍然有相同的错误。
I have been trying to get my dev environment setup on OS X for a couple of days now, and I have had a lot of trouble with mysql. I have installed mysql via the dmg file available from the mysql website. This fixed most of the trouble I was having.
My current problem is that, when I run "rake db:migrate" I get the following error:
rake aborted!
undefined method `init' for Mysql:Class
I read somewhere that using gem 'mysql2' in the Gemfile and mysql2 as the database adapter might fix the problem. I tried doing this, but it did not work. One thing to note is that mysql is not anywhere in my PATH variable, so typing 'mysql' in the terminal takes me to /var/_mysql which is kind of weird.
Do I need to add '/usr/local/mysql/bin' to my path variable? If so, how do I do this in OS X?
Thanks.
EDIT: I added /usr/local/mysql/bin to my path, still have the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了解决这个问题,我最终使用了 mysql2 gem 而不是 mysql gem。这个过程一点也不简单,所以我想发布我所采取的确切步骤,以防以后有人需要帮助。
首先,从 mysql 网站下载与您的 OS X 版本相对应的 OS X DMG 文件。您需要安装 mysql,然后是启动项,最后是首选项面板(所有这 3 个都在 DMG 文件中)。
接下来,您需要将 mysql 添加到路径变量中。我相信您可以编辑 /etc/paths 或向 /etc/paths.rd/ 添加新文件,但我最终修改了终端的配置文件。我将以下行添加到 ~/.zshrc (这仅适用于 zsh,如果您使用 bash,则文件类似于 ~/.bashrc):
[path:variables] 只是所有其他路径变量的占位符在那里。第二行是让 mysql2 gem 工作所需的内容。第二行让mysql找到需要的库文件。
接下来,替换或添加
为
<需要 0.3,否则会抛出一些奇怪的错误。 (抱歉,我没有保存堆栈跟踪)。最后一步是将数据库适配器更改为 mysql2。我希望这可以帮助人们避免很多头痛:)
To fix the problem I ended up using the mysql2 gem instead of the mysql gem. This process was not straight forward at all, so I wanted to post the exact steps I took in case someone needs help later.
First, download the OS X DMG file that corresponds to your version of OS X from the mysql website. You will need to install mysql, then the startup item, and finally the preferences panel (All 3 of these were in the DMG file).
Next, you need to add mysql to your path variable. I believe you can edit /etc/paths or add a new file to /etc/paths.rd/, but I ended up modifying my terminal's configuration file. I added the following line to ~/.zshrc (This is only for zsh, if you use bash the file is something like ~/.bashrc):
[path:variables] is just a place holder for all of the other path variables that were there. The second line is something that was required to get the mysql2 gem working. The second line allows mysql to find a required library file.
Next, replace or add
with
The < 0.3 was required, otherwise some weird errors were thrown. (Sorry, I didn't save the stack trace). The final step is to change your database adapters to mysql2. I hope this can help someone save a great deal of headache :)
我建议您完全卸载 MySQL 和 MySQL gem。然后安装Homebrew包管理器并使用Homebrew安装MySQL。之后安装宝石。在许多情况下,Homebrew 将使您的生活变得更加轻松。如果您对 C 库的安装不太有信心,则特别有用。
I suggest you uninstall MySQL completely and the MySQL gem(s). Then install Homebrew package manager and use Homebrew to install MySQL. After that install the gems. Homebrew will make your life much easier in a number of instances. Particularly helpful if you are not too confident with the installations of C libraries.