Tag: mysql

MySQL2:查询期间与MySQL服务器的连接丢失

当我尝试使用union时,我收到以下错误: ActionView::Template::Error (Mysql2::Error: Lost connection to MySQL server during query: SELECT `apps`.* FROM `apps` WHERE `verve_apps`.`status` IN (1, 2) AND (apps.id IN (SELECT apps.id FROM `apps` WHERE `apps`.`status` IN (1, 2) AND (app_name LIKE ‘%b%’) UNION SELECT apps.id FROM `verve_apps` INNER JOIN taggings ON taggings.taggable_id = apps.id INNER JOIN tags ON tags.id = taggings.tag_id AND […]

在查询随机简单查询时丢失与MySQL服务器的连接

我在rails堆栈上运行ruby,我们的mysql服务器是独立的,但与我们的应用服务器位于同一站点。 (我们已经尝试将其换成不同规格的mysql服务器,但没有看到任何改进。 在工作时间,我们从没有特定查询得到一些这些。 ActiveRecord::StatementInvalid: Mysql2::Error: Lost connection to MySQL server during query 大多数失败的查询都非常简单,并且在一个查询和另一个查询之间似乎没有模式。 这一切都是从我从Rails 4.1升级到4.2时开始的。 我不知道该尝试什么。 我们的数据库服务器全天CPU不到5%。 我确实从随机交互失败的用户那里得到了错误报告,所以这不是那些已经运行了几个小时或类似的事情的查询,当然,当他们重试它完全相同的事情时。 我们的服务器由cloud66配置。 简而言之:我们的mysql服务器由于某种原因而消失,但这不是因为缺乏资源,而是当我们从这个问题开始时从另一台服务器迁移时它也是一台全新的服务器。 在有时开发function时我也会在localhost上发生这种情况,因此我不认为这是一个负载问题。 我们正在执行以下操作: ruby2.2.5 铁轨4.2.6 mysql2 0.4.8 更新:根据下面的第一个答案,我昨晚将max_connections变量增加到500,并通过show global variables like ‘max_connections’;确认增加show global variables like ‘max_connections’; 我仍然得到连接掉线,今天第一个连接只在几分钟前被删除…. ActiveRecord::StatementInvalid: Mysql2::Error: Lost connection to MySQL server during query 我select * from information_schema.processlist;运行select * from information_schema.processlist; 我有36排回来。 这是否意味着我的应用服务器当时正在运行36个连接? 或者一个过程可以是多个连接吗? […]

MySQL2 / Ruby 1.9.3 / Rails上的分段错误3.2

我一直很难让rails 3.2与mysql2一起工作。 我正在运行OSX 10.6,MySQL 5.1.37 我正在获得这个可爱的堆栈跟踪。 HunterMBP:v hunter$ bundle exec rake db:create /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle: [BUG] Segmentation fault ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0] — Control frame information ———————————————– c:0033 p:-543968548 s:0099 b:0099 l:000098 d:000098 TOP c:0032 p:—- s:0097 b:0097 l:000096 d:000096 CFUNC :require c:0031 p:0107 s:0093 b:0093 l:000092 d:000092 TOP /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.2/lib/mysql2.rb:8 c:0030 p:—- s:0091 b:0091 l:000090 […]

DataMapper因关系而无法删除记录

我有许多使用Torrent和Tag的DataMapper / MySQL设置,如下所示: class Torrent include DataMapper::Resource property :id, Serial property :name, String property :magnet, Text property :created_at, DateTime has n, :tags, :through => Resource end class Tag include DataMapper::Resource property :id, Serial property :name, String property :hits, Integer has n, :torrents, :through => Resource end 但是,当试图通过Torrent.first.destroy或类似的东西来破坏一个torrent时,DataMapper会返回false 。 我尝试了直接的SQL查询,例如delete from torrents where name like ‘%ubuntu%’ […]

MySQL,Rails ActiveRecord日期分组和时区

我想按创建日期计算用户数。 当我查询我的上一个用户时,我有: > User.last.created_at => Thu, 07 Aug 2014 21:37:55 BRT -03:00 当我计算每个日期的用户时,我得到这个: > User.group(“date(created_at)”).count => {Fri, 08 Aug 2014=>1} 创建日期是8月7日,但结果是8月8日。这是因为组条件是UTC,我的时区是’Brasilia’。 我在我的application.rb有这个: config.time_zone = ‘Brasilia’ config.active_record.default_timezone = :local 怎么解决这个?

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

Windows XP。 Ruby 1.9.2。 安装了Rails。 MySQL已安装。 当我尝试运行gem install mysql2 (或bundle install )时,我收到错误: C:\ruby\cred2>gem install mysql2 Building native extensions. This could take a while… ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. C:/Ruby192/bin/ruby.exe extconf.rb checking for rb_thread_blocking_region()… *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary […]

耙子流产了! 无法在El Capitan上加载这样的文件 – mysql2 / mysql2

我在过去两周内一直在尝试在Mac上设置我的代码。 以前我使用的是Ubuntu,设置代码从未如此困难。 我几乎遵循了所有教程,但没有运气。 请任何人都可以指导我在mac上设置RoR。 在完成所有教程后,我最终只得到了mysql错误。 rake aborted! cannot load such file — mysql2/mysql2 /Users/sahil/Documents/work/ccprod/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require’ /Users/sahil/Documents/work/ccprod/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `block in require’ /Users/sahil/Documents/work/ccprod/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency’ /Users/sahil/Documents/work/ccprod/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require’ /Users/sahil/Documents/work/ccprod/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `’ /Users/sahil/.rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require’ /Users/sahil/.rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require’ /Users/sahil/.rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `each’ /Users/sahil/.rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `block in require’ /Users/sahil/.rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each’ /Users/sahil/.rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require’ /Users/sahil/.rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.10.6/lib/bundler.rb:134:in `require’ /Users/sahil/Documents/work/ccprod/config/application.rb:9:in `’ /Users/sahil/Documents/work/ccprod/Rakefile:4:in `’ (See full trace by running task […]

试图访问我的ruby项目 – 与mysql有关的LoadError

我正在尝试访问我的第一个ruby项目。 导航到正确的目录并键入: $ rails服务器 我收到以下错误消息: /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in require’: dlopen(/Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError) Referenced from: /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle Reason: image not found – /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in require’: dlopen(/Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError) Referenced from: /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle Reason: image not found – /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in require’: dlopen(/Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError) Referenced from: /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle […]

Ruby和MySQL的UTF-8字符

我正在将Sinatra应用程序从SQLite3切换到MySQL。 出于某些原因,我无法理解,当我使用Ruby和Sequel从MySQL中提取数据时,字符以8-BIT ASCII而不是UTF-8出现。 部署环境是FreeBSD 9.1和MySQL 5.6.12,从FreeBSD端口安装了系统范围的ruby19。 RVM ruby​​-2.0p247产生相同的结果。 我的my.cnf如下: # The following options will be passed to all MySQL clients [client] default-character-set=utf8 #password = your_password port = 3306 socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 128M max_allowed_packet […]

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

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