开发者

Cannot run migrations due to MySQL error

开发者 https://www.devze.com 2023-03-30 17:27 出处:网络
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 websit

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 var开发者_如何学运维iable? 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.


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

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

[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

gem 'mysql' 

with

gem 'mysql2', '< 0.3'

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消