如何跨多个服务器对 Mysql 进行分区?

发布于 2024-08-08 20:46:02 字数 145 浏览 6 评论 0原文

我知道水平分区...您可以创建许多表。

如何使用多个服务器来做到这一点? 这将允许 Mysql 进行扩展。

在 X 服务器上创建 X 表?

有没有人愿意解释一下,或者有一个很好的初学者教程(逐步)来教您如何跨多个服务器进行分区?

I know that horizontal partitioning...you can create many tables.

How can you do this with multiple servers?
This will allow Mysql to scale.

Create X tables on X servers?

Does anyone care to explain, or have a good beginner's tutorial (step-by-step) that teaches you how to partition across multiple servers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

流殇 2024-08-15 20:46:02

对于 MySQL,人们通常会执行所谓的基于应用程序分片

简而言之,您将在多个数据库服务器上拥有相同的数据库结构。但它不会包含相同的数据。

举个例子:

Users 1 - 10000: server A
Users 10001 - 20000: server B

分片(当然)不是一种备份技术,它的目的是跨集群分布读取和写入。

例如,用于分片的技术是 MySQL-Proxy。这不是 HScale 发明的,它或多或少是一个简单的 LUA 脚本,它将读取和写入分发到不同的后端服务器。 MySQL forge 上应该有很多例子。

另一个工具(基于 MySQL Proxy)是 SpockProxy。完全针对分片而定制。他们还摆脱了 Lua,并进行了各种工作以使其比代理更快。到目前为止,我只测试了 SpockProxy,但从未在生产中运行过它。

现在除了这些代理之外,您还可以对自己进行分片。需要一个主表,例如:

-------------------
| userA | server1 |
| userB | server2 |
| userC | server1 |
-------------------

然后构建对服务器的读取和写入。不是很漂亮但是有效。下一个障碍是让它变得更加耐摔。例如,server1server2server3 每个都应该是一个小集群。

最后但并非最不重要的一点是,另一个有趣的跨服务器分区数据和索引的方法是 Digg 的 IDDB。我不确定他们是否发布了其代码,但他们的博客文章提供了有关其功能的详细信息。

让我知道这是否有帮助!

With MySQL, people generally do what is called application based sharding.

In a nutshell, you will have the same database structure on multiple database servers. But it won't contain the same data.

So for example:

Users 1 - 10000: server A
Users 10001 - 20000: server B

Sharding (of course) is not a backup technique, it's meant to distribute reads and writes across a cluster.

Techniques employed to shard are the MySQL-Proxy, for example. This is nothing that HScale invented, it's more or less a simple LUA script which distributes reads and writes to different backend servers. There should be plenty of examples on the MySQL forge.

Another tool (based on MySQL Proxy) is SpockProxy. Completely tailored towards sharding. They also got rid off Lua, and they worked on various things to make it speedier than the proxy. So far, I have only tested SpockProxy, but never ran it in production.

Now aside from those proxies, you can shard yourself as well. Required would be a master table, e.g.:

-------------------
| userA | server1 |
| userB | server2 |
| userC | server1 |
-------------------

Then construct your reads and writes towards the server. Not very pretty but that works. The next obstactle would be to make it more falt tolarant. So for example, server1, server2 and server3 each should be a small cluster.

And last but not least, another interesting approach to partition data and indices across servers is Digg's IDDB. I'm not sure if they ever released its code, but their blog posts gives great details on what it does.

Let me know if this helps!

作死小能手 2024-08-15 20:46:02

但您需要记住,如果您出于某种原因想要将此解决方案引入云并使其成为多租户,那么上述配置可能会变得更具挑战性。考虑一下 -

  1. 您登录到系统,并且根据用户组织表选择数据库(数据库交换)
  2. 这将是您现在正在与它自己的从属设备交谈的新主表
  3. 但是上面的第 2 点也需要分片现在,因为您想确保横向扩展不会成为瓶颈。

所以现在的问题是,您可能需要考虑如何在主从环境中进行分片,其中从设备通常用于读取,主设备用于写入。

干杯!
加里

But you need to keep in mind that if you for some reasons want to take this solution to cloud and make it multi tenant then the above configuration might become more challenging. Think about this -

  1. you logged into the system and the DB gets selected (DB swap) based on the user- organization table
  2. This would be the new Master table that you are talking to now with it's own slaves
  3. But the point 2 above also needs sharding now since you want to make sure that your scale out does not become a bottleneck.

So now the question is that you will probably need to think how can you do this sharding in a mster-slave kind of env where slaves are typically for reading and masters for writing.

cheers !
Gary

人生戏 2024-08-15 20:46:02

HSCALE 0.1 的公告中写道:

现在我们需要分手
桌子很大,但稍后我们想要
将分区分布到多个
MySQL服务器实例拥有真实的
水平扩展。最难的部分
将处理交易
我们必须使用分布式的地方
交易 (XA) 或禁止
涉及分区的事务
不同的主机...

看看这个项目: http://sourceforge.net/projects/hscale/< /a> 也许它适合你。

Here what is written at the announce of HSCALE 0.1:

Right now we need to just split up
huge tables but later on we want to
distribute partitions over multiple
MySQL server instances to have real
horizontal scale out. The hardest part
will be dealing with transactions
where we have to use distributed
transactions (XA) or disallow
transactions involving partitions on
different hosts...

Have a look at this project : http://sourceforge.net/projects/hscale/ maybe it will be suitable for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文