拆分 MySQL 数据库
我有一个关于拆分数据库的问题。这是有问题的查询:
SELECT COUNT(*) FROM monies.link_monies_new lcn '
. 'INNER JOIN products.link l ON lcn.link_id = l.link_id '
. 'INNER JOIN products.products_format af ON l.product_format_id = af.product_format_id '
. 'INNER JOIN products.products_categories ac ON af.product_category_id = ac.product_category_id '
. 'WHERE lcn.click_time BETWEEN FROM_UNIXTIME(1311721200) AND FROM_UNIXTIME(1311807600) '
. 'AND ac.product_category_id = 1
问题是现在数据库资金和产品将位于不同的服务器中。解决办法是什么?我需要两次查询吗?我有点失落。
谢谢!
I have a question about split databases. This is the query in question:
SELECT COUNT(*) FROM monies.link_monies_new lcn '
. 'INNER JOIN products.link l ON lcn.link_id = l.link_id '
. 'INNER JOIN products.products_format af ON l.product_format_id = af.product_format_id '
. 'INNER JOIN products.products_categories ac ON af.product_category_id = ac.product_category_id '
. 'WHERE lcn.click_time BETWEEN FROM_UNIXTIME(1311721200) AND FROM_UNIXTIME(1311807600) '
. 'AND ac.product_category_id = 1
The problem is that now the databases monies and products will be in different servers. What is the solution? Do I need two queries? I am a bit lost.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://dev.mysql.com/doc/refman/5.0 /en/federated-use.html
如果我正确理解了你的问题,你想要在两个数据库之间进行查询连接表,并且数据库将位于不同的服务器上。
假设您在“monies”服务器上运行查询,您将在monies 服务器上创建联合表,指向“products”服务器。这样,您的查询将继续工作,并且 MySQL 神奇地管理它们位于物理上独立的服务器上的事实。
性能调整可能会出现问题,但这是让查询保持现在状态的最简单方法。
例如,您可以在“monies”服务器上创建一个名为“products”的本地数据库;在产品中,您将创建一个“链接”表:
然后您可以运行上面的查询而不进行任何更改。
http://dev.mysql.com/doc/refman/5.0/en/federated-use.html
If I've understood your question properly, you want to have a query joining tables between 2 databases, and the databases will be located on separate servers.
Assuming you run the query on the "monies" server, you would create federated tables on the monies server, pointing at the "products" server. That way, your queries continue to work, and MySQL magically manages the fact they're on physically separate servers.
Performance tuning could be problematic, but it's the simplest way to keep your queries working as they are now.
For instance, you could create a local database on the "monies" server called "products"; within products, you would create a "link" table:
You could then run the query above without changing anything.