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.
我在我的Mac机器上运行XAMPP的mysql和apache(10.6.4)。我通常使用此设置进行PHP开发,但现在我想从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:
不幸的是我无法让mysql与RoR一起工作。我使用XAMPP启动mysql服务器,当我执行“rake db:migrate”时,我得到了这个输出:
!!! 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
mysql位于/ Applications / XAMPP / xamppfiles / bin中,mysql SOCKET位于/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock中
Therefore my database.yml file looks like this:
因此我的database.yml文件如下所示:
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:
我不认为我需要做一个“gem install mysql”,因为mysql已经在运行XAMPP。无论如何我试过但它也失败了:
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
4 个解决方案
#1
8
You need to tell the gem installer the path to your mysql files installed with XAMPP
您需要告诉gem安装程序使用XAMPP安装的mysql文件的路径
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:
还要将正确的套接字添加到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.
之后,再次在rails项目中运行bundle,它应该可以工作。
#2
0
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.
我认为你走在正确的轨道上。你确实需要mysql gem,因为它提供了与mysql交谈的必要文件。它不会安装mysql数据库引擎。
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.
至于为什么mysql gem无法安装,我唯一能想到的是权限问题,但我认为当你运行“gem install mysql”时会在输出中指出。您可以尝试将--backtrace添加到install命令,以查看是否提供了有关失败原因的更多信息。
#3
0
The mysql gem isn't the mysql server, it's the ruby bindings to the mysql api.
mysql gem不是mysql服务器,它是mysql api的ruby绑定。
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
对于安装问题,请查看这个问题,我认为正确的答案非常适合发生的事情:MySQL安装:错误:无法构建gem原生扩展
#4
0
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/"
#1
8
You need to tell the gem installer the path to your mysql files installed with XAMPP
您需要告诉gem安装程序使用XAMPP安装的mysql文件的路径
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:
还要将正确的套接字添加到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.
之后,再次在rails项目中运行bundle,它应该可以工作。
#2
0
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.
我认为你走在正确的轨道上。你确实需要mysql gem,因为它提供了与mysql交谈的必要文件。它不会安装mysql数据库引擎。
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.
至于为什么mysql gem无法安装,我唯一能想到的是权限问题,但我认为当你运行“gem install mysql”时会在输出中指出。您可以尝试将--backtrace添加到install命令,以查看是否提供了有关失败原因的更多信息。
#3
0
The mysql gem isn't the mysql server, it's the ruby bindings to the mysql api.
mysql gem不是mysql服务器,它是mysql api的ruby绑定。
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
对于安装问题,请查看这个问题,我认为正确的答案非常适合发生的事情:MySQL安装:错误:无法构建gem原生扩展
#4
0
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/"