How do I get XAMPP's MySQL and Ruby on Rails work together on my Mac?
I have mysql and apache running through XAMPP on my Mac machine (10.6.4). I usually do PHP development with this setup but
now I want to start out with Ruby on Rails.Unfortunately I cannot get mysql to work with RoR. I start the mysql Server with XAMPP and when I do "rake db:migrate" I get this output:
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql
mysql is located in /Applications/XAMPP/xamppfiles/bin and the mysql SOCKET is in /Ap开发者_开发问答plications/XAMPP/xamppfiles/var/mysql/mysql.sock
Therefore my database.yml file looks like this:
development:
adapter: mysql
database: dbname
username: dbuser
password: dbpw
socket: /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
I don't think I need to do a "gem install mysql" because mysql is already running with XAMPP. Anyhow I tried but it failed also:
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
You need to tell the gem installer the path to your mysql files installed with XAMPP
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/Applications/XAMPP/xamppfiles/lib/mysql --with-mysql-lib=/Applications/XAMPP/xamppfiles/lib/mysql/ --with-mysql-include=/Applications/XAMPP/xamppfiles/include/mysql/
Also add the correct socket to your database.yml:
development:
adapter: mysql2
encoding: utf8
database: your_db
pool: 5
username: root
password:
socket: /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
After that, run bundle
in the rails project again and it should work.
I think you're on the right track. You do need the mysql gem because it provides the necessary files to talk to mysql. It does not install the mysql database engine.
As for why the mysql gem failed to install, the only thing I can think of is a permissions problem but I think that would be indicated in the output when you ran "gem install mysql". You might try adding --backtrace to the install command to see if that provides more information about why it failed.
The mysql gem isn't the mysql server, it's the ruby bindings to the mysql api.
For the install problems, check out this SO question, I think the correct answer is perfect for what's going on: MySQL Install: ERROR: Failed to build gem native extension
Worked for me using this :
sudo gem install mysql2 -- --with-mysql-config="/Applications/XAMPP/xamppfiles/bin/" --with-mysql-include="/Applications/XAMPP/xamppfiles/include/" --with-mysql-lib="/Applications/XAMPP/xamppfiles/lib/mysql/"
精彩评论