Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 /Applications/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.
like image 292
Norwald Avatar asked Aug 15 '10 11:08

Norwald


People also ask

Does Ruby on Rails work with MySQL?

Ruby on Rails uses SQLite as its database by default, but it also supports the use of MySQL.

What database does Ruby on Rails use?

Rails defaults to using a SQLite database when creating a new project, but you can always change it later.


1 Answers

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.

like image 193
tomraithel Avatar answered Sep 24 '22 01:09

tomraithel