Execute SQL statements from Rails console

Source: Internet
Author: User

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,:d ATABASE_TIMEZONE=>:UTC,: Application_timezone=>nil,: Cache_rows=>true ,: connect_flags=>214125,: Cast=>true,:d Efault_file=>nil,:d efault_group=>nil,:adapter=> "Mysql2",: Encoding=> "UTF8",:p ool=>5,:username=> "",:p assword=> ",:host=>" ",:p ort=>3306,:d atabase=>" Cms_production ",:flags=>2}>IRB (main):009:0> R.each {|row|puts row}ott_remote_cms_productioncreate 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,:d ATABASE_TIMEZONE=>:UTC,: Application_timezone=>nil,: Cache_rows=>true ,: connect_flags=>214125,: Cast=>true,:d Efault_file=>nil,:d efault_group=>nil,:adapter=> "Mysql2",: Encoding=> "UTF8",:p ool=>5,:username=> "",:p assword=> ",:host=>" ",:p ort=>3306,:d atabase=>" 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_clientutf8character_set_connectionutf8character_set_databaseutf8character_set_ Filesystembinarycharacter_set_resultsutf8character_set_serverutf8character_set_systemutf8character_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/"]]

Execute SQL statements from Rails console

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.