gpt4 book ai didi

mysql - 通过 bundle (Gemfile) on rails 安装 mysql2 -v '0.3.19'

转载 作者:行者123 更新时间:2023-11-29 01:54:49 25 4
gpt4 key购买 nike

在 OSX Lion 上的 Gemfile 上列出“mysql2”时尝试“捆绑安装”时出现错误。我目前正在使用 Rails 构建一个应用程序。如果我运行“bundle install”,它会永远挂起。首先,我尝试按照建议将 gem 文件修改为 'gem 'mysql2', :git => 'git://github.com/sodabrew/mysql2.git', :ref => 'a2800f'' 来解决这个问题这里:https://github.com/brianmario/mysql2/pull/654 .无限循环得到修复,我成功运行了“bundle install”,但是当我运行“rake db:create”时,出现了这个错误:

rake aborted!
LoadError: dlopen(/Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
Referenced from: /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/config/application.rb:7:in `<top (required)>'
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/Rakefile:4:in `<top (required)>'

我也尝试“brew install mysql”并且成功了,但是在“rake db:create”上,我得到了这个错误:

#<Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)>
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"moviestore_development"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)
#<Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)>
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8","pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"moviestore_test"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)

然后我“brew uninstall mysql”,那个问题就消失了,但现在我有了第一个。

尝试“gem install mysql2 -v '0.3.19'”也会挂起。

可能是什么问题?

最佳答案

当您使用 bundler 时,您必须解决第一个问题(为什么捆绑安装失败)并使用 bundler 安装 mysql2 gem。一定有一些您需要查看的 gem 依赖性问题。

并且,您应该运行:bundle exec rake db:migrate,因为您正在使用 bundler 和 Gemfile 等,这将确保您的 rake 任务在当前项目的上下文中运行。

更新:1

如果您已经成功运行:bundle install 并成功安装了 mysql2 gem,请尝试运行:

`bundle exec rake db:create`

如果这导致您指定的错误(这意味着您的 libmysqlclient 库由于某种原因没有加载):

rake aborted!
LoadError: dlopen(/Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
Referenced from: /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/macbook/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/mysql2-a2800f86754b/lib/mysql2/mysql2.bundle
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/config/application.rb:7:in `<top (required)>'
/Users/macbook/Desktop/tutorial/billingleap2/moviestore/Rakefile:4:in `<top (required)>'

那你应该看看这个answerthis one too其中有一些针对类似问题的规定解决方案。尝试那些看看是否有效。

更新:2

因此,mysql gem 有一些开发依赖项,需要在您实际使用 mysql 之前将其安装到您的系统中。执行以下操作:

sudo gem install mysql-server mysql-client
sudo gem install libmysql-ruby libmysqlclient-dev
sudo gem install mysql

然后再试一次:

bundle install

更新:3

首先,找到你的套接字文件:

mysqladmin variables | grep socket

它会给你这样的东西:

| socket                                            | /tmp/mysql.sock

然后,在您的 config/database.yml 中添加一行:

development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /tmp/mysql.sock

关于mysql - 通过 bundle (Gemfile) on rails 安装 mysql2 -v '0.3.19',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32129819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com