【问题标题】:Is it possible to change the selected database with the Mysql2 gem?是否可以使用 Mysql2 gem 更改所选数据库?
【发布时间】:2012-05-10 09:47:54
【问题描述】:

我想更改 Mysql2::Client 正在使用的数据库(例如,与在 mysql 命令行中键入“use X”相同)而无需与数据库服务器建立新连接。

这可能吗?怎么样?

【问题讨论】:

    标签: mysql ruby mysql2


    【解决方案1】:

    使用select_db

    db = Mysql2::Client.new
    db.select_db('test')
    

    【讨论】:

      【解决方案2】:

      可以使用query方法切换数据库:

      db = Mysql2::Client.new
      db.query('use test')
      # You're now talking to the test database
      db.query('use something_else')
      # You're now talking to the something_else database
      

      【讨论】:

        猜你喜欢
        • 2011-07-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多