标签: mysql2

安装mysql2时出错:无法构建gem原生扩展

我在尝试mysql2为Rails 安装gem 时遇到了一些问题.当我尝试通过运行安装它bundle installgem install mysql2它给我以下错误:

安装mysql2时出错:错误:无法构建gem原生扩展.

我该如何修复并成功安装mysql2

ruby mysql rubygems ruby-on-rails mysql2

472
推荐指数
13
解决办法
25万
查看次数

Rails 4 - Gem :: LoadError:为数据库适配器指定'mysql2',但未加载gem

在我的gemfile中我有:

gem 'mysql2'
Run Code Online (Sandbox Code Playgroud)

我的database.yml如下:

default: &default
  adapter: mysql2
  database: <%= ENV['db_name'] %>
  username: <%= ENV['db_user'] %>
  password: <%= ENV['db_pass'] %>
  host:     <%= ENV['db_host'] %>
  pool: 32
  socket:   <%= ENV['socket'] %>

development:
  <<: *default

production:
  <<: *default
Run Code Online (Sandbox Code Playgroud)

我已经运行了两个bundle update并且bundle install我的Gemfile.lock显示了mysql2.

但是,当我运行时,我rake db:migrate在我的计算机和登台服务器上都得到了这个:

myproject.com(master)$ rake db:migrate
WARNING: Use strings for Figaro configuration. 10000012508 was converted to "10000012508".
WARNING: Use strings for Figaro configuration. 860526407370038 was converted to "860526407370038".
rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails mysql2 ruby-on-rails-4 ruby-on-rails-4.1 ruby-on-rails-4.2

150
推荐指数
6
解决办法
6万
查看次数

mysql2 gem的Gem :: LoadError,但它已经存在于Gemfile中

Gem::LoadError
Specified 'mysql2' for database adapter, but the gem is not loaded.
Add `gem 'mysql2'` to your Gemfile
Run Code Online (Sandbox Code Playgroud)

加载以下文件时发生此错误:

active_record/base
Run Code Online (Sandbox Code Playgroud)

这是我在运行rails服务器时遇到的错误.

The mysql2 gem has been added to the Gemfile as well.
Run Code Online (Sandbox Code Playgroud)

我已经完成了bundle install,并尝试重新启动服务器,但仍然得到错误.

ruby-on-rails mysql2 gemfile

104
推荐指数
7
解决办法
5万
查看次数

Rails 4中的LEFT OUTER JOIN

我有3个型号:

class Student < ActiveRecord::Base
  has_many :student_enrollments, dependent: :destroy
  has_many :courses, through: :student_enrollments
end

class Course < ActiveRecord::Base   
    has_many :student_enrollments, dependent: :destroy
    has_many :students, through: :student_enrollments
end

class StudentEnrollment < ActiveRecord::Base
    belongs_to :student
    belongs_to :course
end
Run Code Online (Sandbox Code Playgroud)

我希望查询Courses表中的课程列表,这些课程在StudentEnrollments表中与特定学生相关联.

我发现也许Left Join是要走的路,但似乎rails中的join()只接受一个表作为参数.我认为可以做我想要的SQL查询是:

SELECT *
FROM Courses c LEFT JOIN StudentEnrollment se ON c.id = se.course_id
WHERE se.id IS NULL AND se.student_id = <SOME_STUDENT_ID_VALUE> and c.active = true
Run Code Online (Sandbox Code Playgroud)

如何以Rails 4方式执行此查询?

任何输入都表示赞赏.

sql ruby-on-rails mysql2 ruby-on-rails-4 rails-activerecord

76
推荐指数
10
解决办法
8万
查看次数

Ruby gem mysql2安装失败

当我尝试安装mysql2 gem时,它失败并没有明显的错误.有谁知道如何解决这个问题,所以mysql2安装?

$ sudo gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
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... no …
Run Code Online (Sandbox Code Playgroud)

ruby mysql rubygems libmysql mysql2

71
推荐指数
6
解决办法
8万
查看次数

mysql2 gem编译为错误的mysql客户端库

当尝试通过我的rails应用程序连接到mysql服务器时,我收到以下错误

D:/Program_Files/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.0.27. (RuntimeError)
Run Code Online (Sandbox Code Playgroud)

我怎样才能纠正它?

mysql windows ruby-on-rails mysql2

64
推荐指数
3
解决办法
6万
查看次数

尝试使用mysql2 gem安装应用程序时出错

我试图安装一个使用mysql2gem的开源rails 3.2.21应用程序,但是当我尝试运行bundlecommant时,我收到以下错误:

Fetching: mysql2-0.3.18.gem (100%)
Building native extensions.  This could take a while...
p
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    /Users/my_username/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150614-72129-orqsb7.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know …
Run Code Online (Sandbox Code Playgroud)

ruby mysql ruby-on-rails mysql2 ruby-on-rails-4

64
推荐指数
9
解决办法
2万
查看次数

错误:无法构建gem原生扩展(rails 3.2.3上的mysql2)

我正在尝试使用Rails 3.2.3安装mysql2 gem并且它失败了:

?  bundle install
Fetching gem metadata from https://rubygems.org/.........
Using rake (0.9.2.2) 
Using i18n (0.6.0) 
Using multi_json (1.2.0) 
Using activesupport (3.2.3) 
Using builder (3.0.0) 
Using activemodel (3.2.3) 
Using erubis (2.7.0) 
Using journey (1.0.3) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.2) 
Using actionpack (3.2.3) 
Using mime-types (1.18) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.4.4) 
Using actionmailer (3.2.3) 
Using arel (3.0.2) 
Using tzinfo (0.3.32) 
Using activerecord (3.2.3) …
Run Code Online (Sandbox Code Playgroud)

mysql ruby-on-rails mysql2

48
推荐指数
4
解决办法
4万
查看次数

Mac OSX上的Mysql 5.6令人头疼

我和我的几位同事最近在我们的Mac上使用自制程序从MySQL 5.5升级到MySQL 5.6,在升级服务器之前在本地进行测试.自从这次升级以来,我们在运行rails代码时都遇到了间歇性的MySQL错误:

Lost connection to MySQL server at 'sending authentication information', system error: 32

我们已经尝试在我们的数据库中重新创建用户名和密码,并提高连接超时,但都没有解决问题.错误日志没有提到问题.当我们遇到问题时,我们发现的唯一解决方法是杀死mysql并重新启动它.我最近mysql -u root -p在命令行上使用过这个错误.似乎一旦我开始收到此错误,无论我使用什么用户名,我都无法超过当前的连接数.如果我关闭连接,那么我可以重新打开一个连接.

我们有以下环境:

  • 我们中的一些人:Rails 3.2,Ruby 2,mysql2 0.3.13,MySQL 5.6.12,Mac OSX 10.8.4
  • 我们其他人:Rails 3.2,Ruby 1.9,mysql2 0.3.13,MySQL 5.6.10,Mac OSX 10.8.4

可能导致这种情况的任何想法?

谢谢!朱丽叶

mysql mysql2 ruby-on-rails-3

48
推荐指数
3
解决办法
2万
查看次数

在Rails中创建主键的表和问题

当我尝试使用Mysql2作为数据库管理器在Rails中运行以下代码时:

rake db:migrate
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

 rake aborted!
 "Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL:"
Run Code Online (Sandbox Code Playgroud)

如果默认情况下表中的主键不是"null",为什么会出现此错误?

但是,迁移代码:

class CreateUsers < ActiveRecord::Migration
   def change
    create_table :users do |t|
     t.string "first_name"
     t.timestamps
    end
   end 
end
Run Code Online (Sandbox Code Playgroud)

mysql ruby-on-rails primary-key mysql2

44
推荐指数
2
解决办法
2万
查看次数