所有,
我下载/安装了1.9.2 windows安装程序,然后安装了RubyMine3.0RC,并安装了它.
打开一个新的Rails项目,选择mysql作为DB,当我"运行"它时会出现以下错误.
D:\ProgramFiles\Ruby192\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/Rob/RubymineProjects/test1/script/rails server -p 3000 -b 127.0.0.1 -e development
D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': 126: The specified module could not be found. - D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError)
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2.rb:7:in `require'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2.rb:7:in `<top (required)>'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `block (2 levels) in require'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `block in require'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
from C:/Users/Rob/RubymineProjects/test1/config/application.rb:7:in `<top (required)>'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from D:/ProgramFiles/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
from …Run Code Online (Sandbox Code Playgroud) 我正在玩mysql2(和mysql 5)gem以及结果和Enumerable结果.
我可以运行诸如的查询
results = client.query("select now()")
Run Code Online (Sandbox Code Playgroud)
我也可以运行诸如此类的查询
results = client.query("select version()")
Run Code Online (Sandbox Code Playgroud)
但我想要做的就是把它提升一个档次.在现实生活中,我假设人们运行多个查询.那么我怎样才能确保我能一次性获得版本和时间.
-
我尝试过的东西不起作用:
results = client.query("select version(); select now()")
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Mysql2::Error: You have an error in your SQL Syntax; check the manual that corresponds to your Mysql Version for the right syntax to use near 'select now()' at line1
Run Code Online (Sandbox Code Playgroud)
现在我明白我可以在Mysql Console中运行以下查询并获得结果,我将如何在Mysql2 Gem中做同样的事情:
select version();select now()
Run Code Online (Sandbox Code Playgroud)
我如何在一个命令行中使用Mysql2 gem(或者我需要两个).我问,因为在现实生活中,人们通常会运行多个查询,以便按照他们想要的方式获得结果.
步骤1: -
rails s/usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2.rb:8:in `require': dlopen(/usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle
Reason: image not found - /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2.rb:8:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `block in require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler.rb:120:in `require'
from /Users/mohit/projects/lbs_admin/config/application.rb:7:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Run Code Online (Sandbox Code Playgroud)
第2步: - …
尝试运行$ rails console时出错
/Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2.rb:8
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
from /Users/ccool2486/Sites/test3mysql/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:21:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:21
from script/rails:6:in `require'
from script/rails:6
ccool-2:test3mysql ccool2486$ rails console
WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1 …Run Code Online (Sandbox Code Playgroud) 我有一个用户对象,我通过简单的调用暴露:
@users = User.all
Run Code Online (Sandbox Code Playgroud)
在我使用自定义SQL生成结果的地方,我也有一些更昂贵的查询.
@comment_counts = User.received_comment_counts
Run Code Online (Sandbox Code Playgroud)
此调用和其他类似的调用将返回按ID排序的列表中每个用户一个元素的对象.
在我看来,我想同时遍历用户和comment_counts对象.例如:
for user, comment_count in @users, @comment_counts do
end
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何做到这一点.我似乎也无法弄清楚如何从@comment_counts结果中获取单个记录而不通过@ comment_counts.each运行它
是不是有某种方法可以为每个lits对象构建迭代器,将它们转储到while循环中并在循环的每次传递中单独执行迭代器?此外,如果您可以回答这个问题,我可以在哪里学习如何逐步浏览rails中的列表.
为了在mac上构建ruby 1.9,我必须安装gcc 4.6.Rails和一堆其他宝石很好.安装mysql或mysql2给了我各种心痛.
Run Code Online (Sandbox Code Playgroud)rubygems> env ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.
/Users/ff/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to …Run Code Online (Sandbox Code Playgroud) 我有一个干净的构建系统如下
Ubuntu 11.04
Rvm 1.13.5
Ruby 1.9.3p194
Rails 3.2.3
宝石1.8.24
MySql 5.5.24-1(安装在/ usr/local中)
我正在尝试安装mysql2 gem(0.3.11)并遇到以下问题:
pal@smurf01:~$ sudo gem install mysql2
[sudo] password for pal:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
compiling client.c
client.c: In function 'rb_raise_mysql2_error':
client.c:98:3: warning: ISO C90 forbids mixed …Run Code Online (Sandbox Code Playgroud) 虽然我研究了无数相关的线程,但我对Rails 3应用程序的Mysql连接没有任何麻烦.我的错误信息:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect': Can't connect to MySQL server on 'localhost' (10061) (Mysql2::Error)
Run Code Online (Sandbox Code Playgroud)
(在将此标记为重复问题之前,请考虑是否可以找到另一个我没有遵循的相关建议的主题.)
到目前为止我的努力:
我已将libmysql.dll文件复制<mysql installation>/bin到<ruby installation>/bin.
我在bundle中有mysql2 gem,它是用connector(--with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32)安装的:
> bundle show mysql2
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32
Run Code Online (Sandbox Code Playgroud)
我相信我的database.yml文件配置正确:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: tq_development
pool: 5
username: root
password: pinney
host: localhost
Run Code Online (Sandbox Code Playgroud) 我正试图在我的debian 7盒子上使用ruby 2.0和rails 4一起运行,并且我在使用mysql2 gem连接到mysql数据库时遇到问题.
我使用下面的命令来设置周围的一切:
\curl -L https://get.rvm.io | bash -s stable rvm install ruby rvm use ruby --default rvm rubygems current gem install rails --no-ri --no-rdoc
当我尝试运行rake db:create时,我收到了以下错误:
no implicit conversion of Fixnum into String
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:72:in `create'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:86:in …Run Code Online (Sandbox Code Playgroud) 我正在使用Windows 7并创建与MySQL2的连接.我需要安装gem.我正在遵循这些步骤.有人可以评论一下:
将以下内容添加到Gemfile: gem 'mysql2', '~> 0.3.15'
运行以下命令cmd:gem install mysql2 -v '0.3.15'
使用cmd转到应用程序并运行以下代码: bundle install
当我执行步骤(3)时,我收到以下错误:
安装mysql2(0.3.15)时发生错误,捆绑器无法继续确保`gem install mysql2 -v"0.3.15"'在捆绑之前成功.
我的应用程序驻留在D驱动器上,我使用的是Windows 7.