由于MySQL错误而无法运行迁移 [英] Cannot run migrations due to MySQL error

查看:165
本文介绍了由于MySQL错误而无法运行迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来,我一直在尝试在OS X上安装我的开发环境,而mysql却给我带来了很多麻烦.我已经通过mysql网站上的dmg文件安装了mysql.这解决了我遇到的大部分麻烦.

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.

我当前的问题是,当我运行"rake db:migrate"时,出现以下错误:

My current problem is that, when I run "rake db:migrate" I get the following error:

耙子中止了!
Mysql:Class的未定义方法'init'

rake aborted!
undefined method `init' for Mysql:Class

我在某处读到,在Gemfile中使用gem'mysql2'和mysql2作为数据库适配器可以解决此问题.我尝试这样做,但是没有用.需要注意的一件事是mysql不在我的PATH变量中的任何地方,因此在终端中键入"mysql"会将我带到/var/_mysql,这有点奇怪.

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.

我需要在路径变量中添加'/usr/local/mysql/bin'吗?如果是这样,我该如何在OS X中执行此操作?

Do I need to add '/usr/local/mysql/bin' to my path variable? If so, how do I do this in OS X?

谢谢.

我将/usr/local/mysql/bin添加到我的路径中,仍然有相同的错误.

I added /usr/local/mysql/bin to my path, still have the same error.

推荐答案

为解决此问题,我最终使用了mysql2 gem而不是mysql gem.这个过程一点也不简单,因此我想发布我所采取的确切步骤,以防以后有人需要帮助.

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.

首先,从mysql网站下载与您的OS X版本相对应的OS X DMG文件.您将需要安装mysql,然后安装启动项,最后安装首选项面板(所有这三个都在DMG文件中).

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).

接下来,您需要将mysql添加到您的path变量中.我相信您可以编辑/etc/paths或将新文件添加到/etc/paths.rd/,但最终还是修改了终端的配置文件.我在〜/.zshrc中添加了以下行(这仅适用于zsh,如果您使用bash,则该文件类似于〜/.bashrc):

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):

export PATH=[path:variables]:/usr/local/mysql/bin
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"

[path:variables]只是那里所有其他路径变量的占位符.第二行是使mysql2 gem运行所需的内容.第二行允许mysql查找所需的库文件.

[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.

下一步,替换或添加

gem 'mysql' 

gem 'mysql2', '< 0.3'

<要求为0.3,否则会引发一些奇怪的错误. (对不起,我没有保存堆栈跟踪).最后一步是将数据库适配器更改为mysql2.我希望这可以帮助某人省下很多头痛:)

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错误而无法运行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆