Tag: mysql2

Ruby / MySQL获取单行但仍使用.each?

我正在使用MySQL2 Ruby驱动程序 – 但它似乎有点多余必须调用 result.each{ |r| puts r[‘name’] } 对于返回的单行数据。 必须有一种更简单的方法来获取我想要的mysql字段而不必使用each块?

使用mingw编译mysql2时出现分段错误

当我尝试创建一个Rails服务器时,这就是我得到的。 它立即运行超过500行代码并返回此消息。 这是我的第一个Ruby on Rails项目。 我对编码也很陌生。 如果可能的话,会爱一些帮助。 谢谢! C:/Ruby200-x64/lib/ruby/gems/2.0.0/extensions/x64-mingw32/2.0.0/mysql2-0.3.15/my sql2/mysql2.so: [BUG] Segmentation fault ruby 2.0.0p451 (2014-02-24) [x64-mingw32] 0 enumerator.so 1 C:/Ruby200-x64/lib/ruby/2.0.0/x64-mingw32/enc/encdb.so 2 C:/Ruby200-x64/lib/ruby/2.0.0/x64-mingw32/enc/iso_8859_1.so 3 C:/Ruby200-x64/lib/ruby/2.0.0/x64-mingw32/enc/trans/transdb.so 4 C:/Ruby200-x64/lib/ruby/2.0.0/x64-mingw32/rbconfig.rb 5 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/compatibility.rb 6 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/defaults.rb 7 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/deprecate.rb 8 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/errors.rb 9 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/version.rb 10 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/requirement.rb 11 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/platform.rb 12 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/basic_specification.rb 13 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/stub_specification.rb 14 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/util/stringio.rb 15 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb 16 C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/exceptions.rb 17 C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/defaults/operating_system.rb 18 C:/Ruby200-x64/lib/ruby/2.0.0/x64-mingw32/enc/utf_16le.so […]

rake db:migrate的问题 –

我无法为Ruby on Rails设置我的MySQL数据库。 设置数据库并确保config / database.yml文件匹配后,我遇到了下面的错误消息。 U:\Rails\alpha>rake db:migrate –trace (in U:/Rails/alpha) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate rake aborted! Access denied for user ‘admin’@’207-237-91-100.c3-0.avec-ubr13.nyr-avec.n y.cable.rcn.com’ (using password: YES) C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/client.rb: 37:in `connect’ C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/client.rb: 37:in `initialize’ C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/con nection_adapters/mysql2_adapter.rb:14:in `new’ C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/con nection_adapters/mysql2_adapter.rb:14:in `mysql2_connection’ C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio n_adapters/abstract/connection_pool.rb:230:in `send’ C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio n_adapters/abstract/connection_pool.rb:230:in `new_connection’ C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio […]

Rails 5和Ruby 2.3.3无法加载libmysql.dll

在为使用mysql数据库创建的应用程序启动服务器时,在控制台中记录下面的错误消息。 Failed to load libmysql.dll from C:\RailsInstaller\Ruby2.3.0\lib\ruby\gems\2.3.0\gems\mysql2-0.4.7-x86-mingw32\vendor\libmysql.dll 环境细节: Window 7 64 bit Rails 5.0.4 ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32] mysqld Ver 5.7.18 for Win64 on x86_64 (MySQL Community Server (GPL)) 来自mysql2 ruby​​ gem的安装后消息在控制台上收到以下消息。 You’ve installed the binary version of mysql2. It was built using MySQL Connector/C version 6.1.10. It’s recommended to use the exact […]

Ruby mysql2在单个查询中有多个语句

我有一个问题,我正在更新我的数据库中的数百万行,所以我不想单独更新每一行,而是希望将〜1000个语句组合并到一个查询中。 我已经启用了MULTI_STATEMENTS client = Mysql2::Client.new(:host => ‘localhost’, :database => ‘mehdb’, :username => “root”, :password => “”, :flags => Mysql2::Client::MULTI_STATEMENTS) 这是我正在运行的代码的示例 sql = “SELECT id, x FROM pew WHERE x IS NULL LIMIT 1000″ results = db_read.query(sql) while results.count > 0 updates = ” results.each do |r| updates += “UPDATE pew SET x = 10 WHERE […]

在Debian Squeeze上安装mysql2 gem时出错

在Debian Squeeze上安装mysql2 gem时出现这个“流行”错误: gem install mysql2 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.2-p290/bin/ruby extconf.rb checking for rb_thread_blocking_region()… yes checking for rb_wait_for_single_fd()… no checking for mysql.h… yes checking for errmsg.h… yes checking for mysqld_error.h… yes creating Makefile make gcc -I. -I/usr/local/rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/i686-linux -I/usr/local/rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 […]

安装Mysql2 gem- 10.6服务器时出错

我正在尝试在10.6服务器上安装mysql2 gem,我收到一条错误消息,我没有看到: EBuilding 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.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 […]

如何使用em_mysql2解决’连接仍在等待结果’错误

我在Goliath(eventmachine)下使用em_mysql2的activerecord。 我的用户模型发生了最奇怪的事情。 当我第一次对/ users进行POST时,它只能按预期找到。 当我做第二次POST时,我收到错误。 Mysql2::Error: This connection is still waiting for a result, try again once you have the result: INSERT INTO `users` (… and so on …) 对于我的任何其他模型或路线,都不会发生这种情况。 我假设如果数据库连接处于混乱状态,我会在其他请求上看到相同的错误但是没有 – 所有其他数据库更新和GET请求似乎都可以正常工作。 有谁知道这只会发生在我的用户模型和仅用于User.save操作的情况下? 活动记录是否以某种方式存储它用于执行Model.save的数据库连接并重新使用它? 编辑: 当我写这个问题时我不知道提到我使用ActiveRecord作为ORM。 我也没有提到我异步向Mongo数据库发送请求以获取用户身份validation信息。 我的解决方案 事实certificate,这个错误发生的唯一时间是来自Mongo的响应在MySQL的响应之前回来,这导致MySQL响应被不同的光纤拾取而不是发出请求的光纤。 由于我使用的MySQL2光纤实现使用光纤的objectID来管理连接,这似乎导致了这个问题。 ActiveRecord + MySql2 + Fibers + Goliath中的整体连接池不是完全支持的配置。 (从那时起可能会有一些进展)

-Fatal-无法分配内存 – Rails 3.1和Mysql2 Gem

我遇到了一个奇怪的问题,最新的’mysql2’gem和Rails 3.1当我包含gem时我可以从IRB运行mysql,但是每当我试图在控制台中保存到数据库时,我都可以运行rails,甚至加载服务器启动时的页面,我得[致命]无法分配内存 。 似乎没有任何可用的mysql日志,这是Rails显示的唯一错误。 有趣的是,当我在Rails控制台中启动连接并运行计数查询(例如User.count)时,它工作正常,但是当我尝试退出控制台时,它会无限期挂起 。 我正在配对的所有人都使用相同的代码库和数据库结构并且没有问题…… 其他人有这种问题吗? 我昨天尝试卸载并重新安装自制程序和mysql,但它仍然会发生。

mysql2 gem 0.3.15给出ASCII-8BIT,编码设置为“utf8”

我使用MySQL 5.1.71和Rails 4.0.4在Ruby 2.0.0-p353上运行(通过rbenv + ruby​​-build),使用mysql2 gem 0.3.15。 CentOS 6.5。 在database.yml中,编码设置为“utf8”,适配器为“mysql2”,适用于所有环境。 我的表都使用UTF-8,“DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci”。 在Ruby中, Encoding::default_internal == Encoding::default_external == Encoding::UTF_8 。 关于ActiveRecord为什么还给我ASCII-8BIT字符串的原因,我还能看到其他任何想法? 我在Mac上开发了UTF-8,但在Linux上生产的是ASCII-8BIT。 当我启动一个控制台并直接使用mysql2时,我得到了ASCII,所以这似乎是问题所在。 mysql> SHOW VARIABLES LIKE ‘character_set%’; +————————–+—————————-+ | Variable_name | Value | +————————–+—————————-+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | […]