Ruby on Rails environment to build MySQL database connection

Source: Internet
Author: User
Tags file copy phpmyadmin ruby on rails

1. Install wamp1.7.4 to automatically install Apache and Mysql,apache ports may be occupied by IIS services, you can go to the control panel to shut down

2. Change the root password, in order to continue to operate the database in the phpMyAdmin, need to Wamp installation path in the phpMyAdmin to find config.inc.php, file search "password", the original

Blank password modified to "root", restart Wamp, you can access the phpMyAdmin

3. Copy the Libmysql.dll from the bin directory in the MySQL installation directory to the bin directory of the Ruby installation directory (my c: \ruby\bin , which is modified with your own Ruby installation path)

4. To https://rubygems.org/gems/rdoc/versions download Rdoc-2.4.3.gem then copy the Rdoc-2.4.3.gem to the D:ror directory (the directory is built by me, the reader is free), then the command line:

CD D:\ror

Gem Install Rdoc-2.4.3.gem

The move is for a smooth installation of MySQL for Ruby documentation later

5. To https://rubygems.org/gems/rdoc/versions search download Download mysql gem driver file, I downloaded the Mysql-2.8.1.gem, copied to the D:ror directory (the directory is built by me, the reader can freely )

Install MySQL for Ruby driver, command line type: Gem install Mysql-2.8.1.gem

6. Go to http://download.csdn.net/detail/luoyeyilin/3614807 download Instantrails-2.0-win.zip extract, search under mysql.so,80k size file Copy the mysql.so to the C:\RUBY\LIB\RUBY\SITE_RUBY\1.8\I386-MSVCRT.

You can then connect in the code (the limited need to create a new person table in database test with navicate for MySQL, create two column IDs and Name,,id set as the primary key, and then assign several initial values):

And then you can write the program to connect

1 #ENCODING:GBK2Require'MySQL'3 puts Mysql::version4Dbc=mysql.real_connect ('127.0.0.1','Root','****','Test')5Res=dbc.query ('Select Id,name from person')6  whilerow=Res.fetch_row Do7Puts"#{row[0]},#{row[1]}"8End

The results are as follows:

20703
1,???
2,jack
3,rose

Ruby on Rails environment to build MySQL database connection

Related Article

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.