English 中文(简体)
3. 与根据守则设立的MySQL总经理建立联系
原标题:Connect to a MySQL master-master setup from code

For a new website we must connect to a MySQL master-master setup. This is a .NET website using NHibernate, but the same would also apply to Java or any other language. We chose this setup because we want the site to continue working if a database would go down. We don t like downtime.

Maybe I have a complete misunderstanding of how a master-master setup works (in MySQL), but the way I see it, you connect to your database as you d normally do, but behind the scenes, MySQL replicates the data between the two databases. If you do a write, it can go to either master 1 or master 2, you normally wouldn t know (except that the auto-increment id would return a different value). If master A would somehow fail, master B will still work, thus no downtime, master A will be ignored until it goes up again, the data is replicated, and if all is well, master A will be back in the field again.

红十字与红新月联会是正确的,如果我的上述影响是错的,请更正我,如果一位主人倒,你是否需要做任何特殊的事情? 如果我与192.168.1.50(主编A)挂钩,如果主编A倒台,情况如何? MySQL公司是否将我自动与192.168.1(B)连接起来,以便我的网站继续工作?

如果我是NOT正确的话,MySQL总经理的复制工作如何? 我是否必须告诉每个问题,执行谁? 这样做是毫无道理的,因为如果A总公司倒台,那么我对A总公司的所有询问都会失败,而总经理的设立根本无助于我。

因此,我认为我的问题是:

do I still connect to a single MySQL host (I m using NHibernate but that doesn t really matter), do I specify a single connectionstring, and will MySQL know that there are two masters, or does my code change in such a way that I need to specify connectionstrings for both masters (how?), do some special magic to balance the queries between the two servers, etcetera.

我没有任何东西? 感谢!

最佳回答

也许我完全不理解主线主编如何工作(在MySQL),但我认为这样做的方式是,你通常与你的数据库连接,但在幕后,MySQL复制两个数据库的数据。 如果你写了字,可以去看主1或主2,你通常会知道(但汽车加油回价不同)。

这是不正确的。

MySQL复制作品,撰写了承诺的数据(视复制方式,将改换的行状或实际的书表K与复制记录联系起来),然后将这一标识运到奴隶们,他们在那里重新发挥作用并作出同样的改变。

在多家大师的复制中,每个节点既是主人,又是奴隶,从前台机器中获取最新信息,并将其转交下台机器。 每个机器都有一个独特的识别标志,在发送和接收复制记录时使用,从而能够确定数据何时全面。

This method is primitive but effective. It s also traditionally been a real pain in the rear end to manage and maintain. If at all possible, don t use multi-master in favor of other solutions. I use multi-master in production, and can say this from experience.

If I connect to 192.168.1.50 (which is master A), what happens if master A goes down? Will MySQL somehow automagically connect me to 192.168.1.51 (master B) so my site will continue to work?

当你把一台机器连接到一个多端总机时,你是只有<>与一台机器相连的。 如果你需要能够与多台机器连接,如果一台机器倒闭的话,那么你将需要通过修改你的代码或中间负荷平衡来人工处理这种情况。

更糟糕的是,如果一个机器在座does上下台,该机便被打破。 请允许我说,你有三个,即A、B和C。 休息时间为A =>B =>C =>A。 如果B倒塌,A不能再向C转递最新情况,也就是说,C将成为连接起来的唯一安全机器,直到B回落和恢复 lo。

关于自动计算,请见:code>auto_increment_increment和,两个服务器变量使多技术主管复制机自动安装。 在任何情况下,你都不应在多任校长中使用自动加固,而不必确定这两个变量。

问题回答
Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

你可以利用这一联系。 但一只 did。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...