How to select MySql adapter for Ruby applications

Source: Internet
Author: User

Previously, rails2.2 installed the MySQL driver by default, and then changed to sqlite3 by default. If you are connected to MySQL, you need to install it on your own.
When learning open-source systems, we found that some rails3 applications directly use mysql2.


In database. yml, the method is as follows:

Development:
Adapter: mysql2
Encoding: utf8
Database: baseapp
Username: Root
Password:
HOST: localhost

 

After the GitHub query, there is a comparison of three Ruby MySQL adapters (traversal of 30 thousand rows of data ):

 
User System Total real
Mysql2
0.750000 0.180000 0.930000 (1.821655)
Do_mysql
1.650000 0.200000 1.850000 (2.811357)
MySQL
7.500000 0.210000 7.710000 (8.065871)

 

It can be seen that the performance of mysql2 is much higher.

 

Note:

In Windows and Linux environments, the following error occurs:

Building native extensions. This cocould take a while...
Error: Error installing mysql2:
Error: failed to build gem native extension.

...

1. Windows solution: Copy libmysql. dll under bin in the MySQL installation directory to the ruby installation directory/lib.

2. Linux solution: find two files in the system: libmysqlclient. So, the directory where mysql. H is located, for example,/a and/B, and then perform the following operations:

Gem install mysql2 -- with-mysql-Lib =/A -- With-mysql-include =/B

PassSource codeSuch files are usually used to install MySQL.
If not, you need to download it online.Libmysqlclient-Dev
.


 

Today I encountered a new problem:

Ruby1.8.7, rails2.3.8, after gem install mysql2, always prompt when entering the console status

D:/ir3/Ruby/lib/Ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb: 76: In
'Establish _ connection': runtimeerror: Please install the mysql2 adapter:
'Gem install activerecord-mysql2-adapter '(no such file to load --
Java)

What does this have to do with Java?

So delete the gem package related to JDBC and the prompt is changed to the following:

D:/ir3/Ruby/lib/Ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb: 76: In
'Establish _ connection': runtimeerror: Please install the mysql2 adapter:
'Gem install activerecord-mysql2-adapter '(no such file to load --
Active_record/connection_a
Dapters/mysql2_adapter)


But the gem install activerecord-mysql2-adapter is not available at all, that is, this gem package is not available.


Therefore, add the MySQL directory by referring to reinstalling mysql2 in Linux;

Gem install mysql2 -- with-mysql-Config = D:/ir3/MySQL

After the installation is successful, run the ruby script/console without prompting any errors.

However, in the test, check the class, type the user, and the returned result is normal. But to view a record, for example, user. First, the error "argumenterror: Invalid date" appears.

Hi, in windows, back to MySQL now.

Fashion Java-JavaScript mogujie.com women's clothing

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.