如何安装 Rails MySQL 适配器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4597071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I install the Rails MySQL adapter?
提问by Jason Swett
There's not much more to my question than that. gem install mysql
doesn't work and I haven't found anything by Googling.
我的问题仅此而已。gem install mysql
不起作用,我没有通过谷歌搜索找到任何东西。
When I try gem install mysql2
, this is what I get. I don't know what to do now.
当我尝试时gem install mysql2
,这就是我得到的。我现在不知道该怎么办。
jason@buster:~/projects/mcif-rails$ gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/home/jason/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/jason/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection.
Results logged to /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
回答by Jonathan Lonowski
It looks like you still need to install MySQL's development libraries. These are required for the gem to build successfully on your system.
看来还是需要安装MySQL的开发库。这些是 gem 在您的系统上成功构建所必需的。
[Edit] Seems the RoR Wiki is no longer available. But, Ubuntu has offered their own walkthroughwhich suggests:
[编辑] 似乎 RoR Wiki 不再可用。但是,Ubuntu 提供了他们自己的演练,其中表明:
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient-dev
sudo gem install mysql
See http://wiki.rubyonrails.org/database-support/mysql#installationfor more detail.
有关更多详细信息,请参阅http://wiki.rubyonrails.org/database-support/mysql#installation。
Example: Ubuntu
sudo apt-get install mysql-server mysql-server-5.0 libmysqlclient15off \
libmysqlclient15-dev mysql-client-5.0 mysql-common
sudo apt-get install libmysql++-dev
sudo gem install mysql
示例:Ubuntu
sudo apt-get install mysql-server mysql-server-5.0 libmysqlclient15off \
libmysqlclient15-dev mysql-client-5.0 mysql-common
sudo apt-get install libmysql++-dev
sudo gem install mysql
回答by jasonmklug
I'll just leave this here:
我只是把这个留在这里:
I ran into a similar problem, then realized I couldn't install the mysql2 gem without having MySQL installed on my development machine (even though I'm only using the mysql2 gem to connect to a remote MySQL server).
我遇到了类似的问题,然后意识到如果没有在我的开发机器上安装 MySQL,我就无法安装 mysql2 gem(即使我只使用 mysql2 gem 连接到远程 MySQL 服务器)。
::forehead slap::
::额头一巴掌::
brew install mysql
then, in my Gemfile:
然后,在我的 Gemfile 中:
gem 'mysql2', '~> 0.3.11'
followed by a quick
接着是一个快速
bundle install
Success!
成功!
回答by Kevin Sylvestre
If you are running Rails 3 you should use the mysql2 gem. You can install it with:
如果您正在运行 Rails 3,您应该使用 mysql2 gem。您可以使用以下命令安装它:
gem install mysql2
You will need to first install MySQL and any development headers. This will vary across different operating systems. On Ubuntu, you can run:
您需要先安装 MySQL 和任何开发头文件。这将因不同的操作系统而异。在 Ubuntu 上,您可以运行:
aptitude install mysql-server
aptitude install mysql-client
aptitude install mysql-common
aptitude install libmysql-ruby
aptitude install libmysqlclient-dev
If you are creating a new project, use:
如果要创建新项目,请使用:
rails new sample --database=mysql
cd sample
bundle install
For more details, check out the project repository.
有关更多详细信息,请查看项目存储库。
回答by apneadiving
I assume you are working with Rails.
我假设您正在使用 Rails。
In your Gemfile:
在您的 Gemfile 中:
gem 'mysql2'
Then in your terminal:
然后在您的终端中:
bundle
回答by Michael Durrant
In 2013, Using Ubuntu 12.04, this worked for me:
2013 年,使用 Ubuntu 12.04,这对我有用:
sudo apt-get install mysql-client libmysqlclient-dev
bundle install