You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you specify the init_command option, the SQL string you provide will be executed after the connection is established.
259
259
If `:reconnect` is set to `true`, init_command will also be executed after a successful reconnect.
@@ -400,46 +400,7 @@ There are a few things that need to be kept in mind while using streaming:
400
400
401
401
Read more about the consequences of using `mysql_use_result` (what streaming is implemented with) here: http://dev.mysql.com/doc/refman/5.0/en/mysql-use-result.html.
402
402
403
-
## Active Record
404
-
405
-
To use the Active Record driver (with or without rails), all you should need to do is have this gem installed and set the adapter in your database.yml to "mysql2".
406
-
That was easy right? :)
407
-
408
-
NOTE: as of 0.3.0, and Active Record 3.1 - the Active Record adapter has been pulled out of this gem and into Active Record itself. If you need to use mysql2 with
409
-
Rails versions < 3.1 make sure and specify `gem "mysql2", "~> 0.2.7"` in your Gemfile
410
-
411
-
## Asynchronous Active Record
412
-
413
-
Please see the [em-synchrony](https://github.com/igrigorik/em-synchrony) project for details about using EventMachine with mysql2 and Rails.
414
-
415
-
## Sequel
416
-
417
-
The Sequel adapter was pulled out into Sequel core (will be part of the next release) and can be used by specifying the "mysql2://" prefix to your connection specification.
418
-
419
-
## EventMachine
420
-
421
-
The mysql2 EventMachine deferrable api allows you to make async queries using EventMachine,
422
-
while specifying callbacks for success for failure. Here's a simple example:
423
-
424
-
``` ruby
425
-
require 'mysql2/em'
426
-
427
-
EM.run do
428
-
client1 = Mysql2::EM::Client.new
429
-
defer1 = client1.query "SELECT sleep(3) as first_query"
The mysql2 gem converts MySQL field types to Ruby data types in C code, providing a serious speed benefit.
472
+
473
+
The do_mysql gem also converts MySQL fields types, but has a considerably more complex API and is still ~2x slower than mysql2.
474
+
475
+
The mysql gem returns only nil or string data types, leaving you to convert field values to Ruby types in Ruby-land, which is much slower than mysql2's C code.
476
+
477
+
For a comparative benchmark, the script below performs a basic "SELECT * FROM"
478
+
query on a table with 30k rows and fields of nearly every Ruby-representable
479
+
data type, then iterating over every row using an #each like method yielding a
480
+
block:
493
481
494
482
``` sh
495
-
user system total real
496
-
Mysql2
497
-
0.750000 0.180000 0.930000 ( 1.821655)
498
-
do_mysql
499
-
1.650000 0.200000 1.850000 ( 2.811357)
500
-
Mysql
501
-
7.500000 0.210000 7.710000 ( 8.065871)
483
+
user system total real
484
+
Mysql2 0.750000 0.180000 0.930000 (1.821655)
485
+
do_mysql 1.650000 0.200000 1.850000 (2.811357)
486
+
Mysql 7.500000 0.210000 7.710000 (8.065871)
502
487
```
503
488
489
+
These results are from the `query_with_mysql_casting.rb` script in the benchmarks folder.
490
+
504
491
## Development
505
492
506
-
To run the tests, you can use RVM and Bundler to create a pristine environment for mysql2 development/hacking.
507
493
Use 'bundle install' to install the necessary development and testing gems:
0 commit comments