码迷,mamicode.com
首页 > 数据库 > 详细

通过rails console执行sql语句

时间:2016-03-30 12:29:00      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

 

$ RAILS_ENV=production bundle exec rails c

 

irb(main):008:0> r = ActiveRecord::Base.connection.execute show create database ott_remote_cms_production
=> #<Mysql2::Result:0x002b338fe61d68 @query_options={:as=>:array, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:utc, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>214125, :cast=>true, :default_file=>nil, :default_group=>nil, :adapter=>"mysql2", :encoding=>"utf8", :pool=>5, :username=>"", :password=>"", :host=>"", :port=>3306, :database=>"cms_production", :flags=>2}>
irb(main):009:0> r.each {|row| puts row }
ott_remote_cms_production
CREATE DATABASE `cms_production` /*!40100 DEFAULT CHARACTER SET utf8 */
=> [["cms_production", "CREATE DATABASE `ott_remote_cms_production` /*!40100 DEFAULT CHARACTER SET utf8 */"]]
> r = ActiveRecord::Base.connection.execute show tables
=> #<Mysql2::Result:0x002b338fe01aa8 @query_options={:as=>:array, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:utc, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>214125, :cast=>true, :default_file=>nil, :default_group=>nil, :adapter=>"mysql2", :encoding=>"utf8", :pool=>5, :username=>"", :password=>"", :host=>"", :port=>3306, :database=>"cms_production", :flags=>2}>
irb(main):016:0> r.each {|row| puts row }
=> []
irb(main):017:0> r = ActiveRecord::Base.connection.execute show variables like "%char%";
irb(main):018:0* r.each {|row| puts row }
character_set_client
utf8
character_set_connection
utf8
character_set_database
utf8
character_set_filesystem
binary
character_set_results
utf8
character_set_server
utf8
character_set_system
utf8
character_sets_dir
/usr/share/mysql/charsets/
=> [["character_set_client", "utf8"], ["character_set_connection", "utf8"], ["character_set_database", "utf8"], ["character_set_filesystem", "binary"], ["character_set_results", "utf8"], ["character_set_server", "utf8"], ["character_set_system", "utf8"], ["character_sets_dir", "/usr/share/mysql/charsets/"]]

 

通过rails console执行sql语句

标签:

原文地址:http://www.cnblogs.com/iwangzheng/p/5336584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!