# MySQL

**URL:** <https://www.ruby-forum.com/t/mysql/88533>\
**Category:** Deployment\
**Created:** [March 12, 2007, 12:24pm UTC](https://www.ruby-forum.com/t/mysql/88533 "2007-03-12T12:24:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [March 12, 2007, 12:24pm UTC](https://www.ruby-forum.com/t/mysql/88533/1 "2007-03-12T12:24:50Z")

</div>

Hi there,

Could you please help me to find some documentation about using Ruby and  
several MySQL servers with one way replication there.

Main idea is to use Masters server for inserting/changing data and Slave  
server for selecting data from DB.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [March 18, 2007, 5:17pm UTC](https://www.ruby-forum.com/t/mysql/88533/2 "2007-03-18T17:17:45Z")

</div>

ActiveRecord – the part of Rails responsible for talking to the  
database – does not support the configuration of multiple data  
sources for the purposes of segmenting reads and writes and directing  
them to different mysql servers on that basis, at this time, as far as  
I know.

There is a submitted but to-date-not-accepted patch to do this. Its  
author considered it “alpha” code at the time. I’ve tested it a bit.  
It does function. If you are interested in pursuing it, I can provide  
patched base.rb and connection\_adapter.rb files for ActiveRecord that  
work circa Rails 1.1.5. The original is here:  
[http://wrath.rubyonrails.org/pipermail/rails-core/2006-July/002019.html](http://wrath.rubyonrails.org/pipermail/rails-core/2006-July/002019.html)

Alternatively, you could use multi-master replication. If you go this  
route you’ll need to address issues pertaining to auto\_increment  
collisions. This is fairly easy with MySQL 5 as it has global  
variables for auto\_increment\_increment and auto\_increment\_offset.

In a multi-master setup you can load balance the connections coming  
from Rails to MySQL in at least three different ways: 1. a hardware  
load balancer, 2. soft load balancing configuration utilizing the  
IP\_VS kernel support in Linux (built in, if you have a fairly recent  
distribution), or 3. by manipulating the relevant Rails application  
startup config (database.yml) on a per-rails-server-instance (or per-  
application-deployment-instance) basis.

–  
benjamin

On Mar 12, 4:24 am, Max M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [March 20, 2007, 4:13am UTC](https://www.ruby-forum.com/t/mysql/88533/3 "2007-03-20T04:13:47Z")

</div>

Here’s an alternative–SQLRelay:  
[http://sqlrelay.sourceforge.net/sqlrelay/dropin/mysql.html](http://sqlrelay.sourceforge.net/sqlrelay/dropin/mysql.html)

It leaves the connection pooling and segmenting reads vs. writes to  
the driver (which in turn delegates to the real driver). I haven’t  
used it, but this is the direction I was planning on going after  
talking it over with a few people (and considering such an AR patch).

Let us know how it works out for you if you give it a shot.

seth

---

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [March 20, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/mysql/88533/4 "2007-03-20T15:30:33Z")

</div>

> ActiveRecord – the part of Rails responsible for talking to the  
> database – does not support the configuration of multiple data  
> sources for the purposes of segmenting reads and writes and directing  
> them to different mysql servers on that basis, at this time, as far as  
> I know.

[skip]

> Alternatively, you could use multi-master replication. If you go this  
> route you’ll need to address issues pertaining to auto\_increment  
> collisions. This is fairly easy with MySQL 5 as it has global  
> variables for auto\_increment\_increment and auto\_increment\_offset.

[skip]

> –  
> benjamin

Hi,

Thanks for this guide light. I will think about patch.

As About two-way replication then I thought about it.  
Unfortunately I do not have experience with it. I am only using one-way  
(old approved method).  
Could please you share your experience if you have used MySQL with  
two-way replication and give me your feedback how it works.

Thanks again.

---

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [March 22, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/mysql/88533/5 "2007-03-22T19:18:43Z")

</div>

Has anyone tried the beta MySQL-HA (High Availability) stuff with  
Rails?

We currently have a Dual Master MySQL setup but are basically just  
pointing everything to one of the servers right now…

MySQL-HA project site - [http://sourceforge.net/projects/mysql-ha/](http://sourceforge.net/projects/mysql-ha/)  
MySQL-HA home page - [http://www.seriema-systems.com/mysql-ha/](http://www.seriema-systems.com/mysql-ha/)  
MySQL-HA blog - [http://gnuserland.blogspot.com/](http://gnuserland.blogspot.com/)

On Mar 12, 5:24 am, Max M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [May 1, 2007, 11:55am UTC](https://www.ruby-forum.com/t/mysql/88533/6 "2007-05-01T11:55:13Z")

</div>

benjamin wrote:

> ActiveRecord – the part of Rails responsible for talking to the  
> database – does not support the configuration of multiple data  
> sources for the purposes of segmenting reads and writes and directing  
> them to different mysql servers on that basis, at this time, as far as  
> I know.
> 
> There is a submitted but to-date-not-accepted patch to do this. Its  
> author considered it “alpha” code at the time. I’ve tested it a bit.  
> It does function. If you are interested in pursuing it, I can provide  
> patched base.rb and connection\_adapter.rb files for ActiveRecord that  
> work circa Rails 1.1.5. The original is here:  
> [http://wrath.rubyonrails.org/pipermail/rails-core/2006-July/002019.html](http://wrath.rubyonrails.org/pipermail/rails-core/2006-July/002019.html)

Hello Benjamin,

I have started to implementing this solution and faced with problem ☹

First of all I am not able to apply patch you provided.  
(I am using Rails 1.1.6). So patch should be rather different. I will  
very appreciate if you can guide me where can I find additional  
documentation about it, also may be you can provide me base and  
connection\_adapter files for Rails 1.1.5.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [March 20, 2007, 3:32pm UTC](https://www.ruby-forum.com/t/mysql/88533/7 "2007-03-20T15:32:36Z")

</div>

Seth Fitzsimmons wrote:

> Here’s an alternative–SQLRelay:  
> [Using the SQL Relay drop-in replacement library for MySQL/MariaDB](http://sqlrelay.sourceforge.net/sqlrelay/dropin/mysql.html)
> 
> It leaves the connection pooling and segmenting reads vs. writes to  
> the driver (which in turn delegates to the real driver). I haven’t  
> used it, but this is the direction I was planning on going after  
> talking it over with a few people (and considering such an AR patch).
> 
> Let us know how it works out for you if you give it a shot.
> 
> seth

Hi,

Thanks you for this solution too. 🙂 If I will use it of course I get  
my feedback to you.

---

<div class="post-metadata">

**Author:** ![fangheuschrecke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/58956e/32.png) [@fangheuschrecke](https://www.ruby-forum.com/u/fangheuschrecke)\
**Post date:** [October 5, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/mysql/88533/8 "2007-10-05T16:06:03Z")

</div>

Max M. wrote:

> Hi,
> 
> Thanks for this guide light. I will think about patch.
> 
> As About two-way replication then I thought about it.  
> Unfortunately I do not have experience with it. I am only using one-way  
> (old approved method).  
> Could please you share your experience if you have used MySQL with  
> two-way replication and give me your feedback how it works.
> 
> Thanks again.

Forgot to tell you my feedback.

We have remade source code to use MySQL master for write and MySQL slave  
to reed data. ☹
