Tag: mysql

从控制台删除记录 – Ruby on Rails

我想从控制台删除一条记录。 我通过脚本/控制台登录了 User.find(1).delete $ User.find(1) ActiveRecord::RecordNotFound: Couldn’t find User with ID=1 …….. …….. …….. 一切都看起来很好,直到这里。 但是当我退出控制台并通过脚本/控制台命令返回到控制台时,我能够再次看到id = 1的记录。 数据库不是本地的,我通过提供ip连接到database.yml。 当我尝试在开发本地数据库上做同样的事情时,一切都很好。 有人可以解释发生了什么,我错过了哪里! 谢谢

在Ruby on Rails中动态连接到第二个MySQL数据库

我正在开发一个将迁移用户内容的rails应用程序。 我需要通过表单接收数据库参数并使用它们连接到给定的数据库。 实现这一目标的最佳方法是什么? 我尝试过使用Mysql.real_connect没有任何乐趣。

使用mysql2 gem获取最后插入的id

我有这样的代码: require ‘mysql2’ @db.query(“insert into clients (Name) values (‘#{client}’)”) 我可以使用1个查询返回上次插入的ID吗?

准备好的声明的内部结构是什么样的?

以下是bind_params似乎正在准备 sql语句: stmt = db.prepare( “select * from table where a=? and b=?” ) stmt.bind_params( 15, “hello” ) 所以实际上在stmt中,我们需要有map / array或者最终会映射参数并创建正确的stmt的东西。 在内部执行此操作的最佳方式是什么? 加上字符串我需要额外的预防措施 – 上面的内容必须像“select * from table a a = 15 and b = \”hello \“”一样。 我查看了SQLite3和OCI,他们似乎将这些传递给内部C代码。

如何通过单个SQL查询检索同一数据库表中的“常用”记录?

我正在使用Ruby on Rails(版本3.2.2)和mysql2(版本0.3.11 – MySQL版本5.2.38)。 在讨论“ 如何通过关联表检索一组用户在”常见“中具有的关联对象/记录时 ”*我发现自己处于“特定”情况,我必须找到“关联对象/记录”**通过运行单个 – 出于性能原因 – 在关联数据库表上进行SQL查询。 特别是, 我想这样做只是为了检索前面提到的“关联对象/记录”,其中user_id (表示foreign key “指向” User对象) 和article_id (表示foreign key “指向” Article对象) ) 列值相同 (即, article_id和user_id是“common”)。 在我的案例中,我怎么能/应该检索“关联对象/记录”(可能是通过在Ruby on Rails中使用某些工具和/或SQL /数据库“方式”/“上下文”)? *具体来说,在@Andrew Marshall发布他/她的回答之后。 ** 注意 :那些“关联对象/记录”与has_many :through相关has_many :through Ruby on Rails ActiveRecord::Associations 关联问题中描述的关联 。

如何通过在Ruby Rails平台中运行sql脚本来种子mysql数据库?

我基本上是Ruby程序员和Ruby Rails的初学者。 在java中,要运行种子数据库ant任务,ant任务执行SQL脚本。 SQL脚本基本上是一组insert语句。 我希望在Ruby Rails平台上运行sql脚本必须有一些相当于ant的任务? 编辑回应尼基塔的回答: 虽然可以使用迁移作为播种数据的方式之一。 但我不想重写编写与sql脚本相对应的迁移类。 所以我需要一些解决方案,我必须只执行sql脚本文件。 我想通过sql代码只通过数据库进行管理。

Ruby on Rails服务器无法启动:dyld:惰性符号绑定失败:未找到符号:_mysql_get_client_info

环境(Mac OS X 10.7.2 – Lion): $ ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10] $ rails -v Rails 3.1.3 $ mysql -v Server version: 5.1.44 我尝试运行以下操作,但每次即使应用了来自整个网络的修复程序后,我也会遇到同样的错误: $ rails server dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info Referenced from: /Users/pressplay/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle Expected in: flat namespace dyld: Symbol not found: _mysql_get_client_info Referenced from: /Users/pressplay/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle Expected […]

Percona向后兼容MySQL吗? Ruby in Rails案例

我正在开始一个Ruby on Rails项目,我有兴趣使用Percona作为我的DBMS。 我读过Percona与MySQL工具完全兼容 我想知道我是否可以使用Percona的Ruby on Rails工具(使用MySQL支持)?

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 […]