有没有任何工具可以帮助将 innoDB 表转换为 mysql 集群的 NDB 表?

发布于 2024-09-04 00:56:30 字数 77 浏览 1 评论 0原文

有没有什么工具可以帮助将innoDB表转换为NDB表? 我想要一个工具帮助通过触发器替换所有外键。 我是否必须为每个 FK 手动执行此操作?

is there any tools could help to convert innoDB table into NDB table?
I want a tool help to replace all foreign key by trigger.
Should I have to do it by manual for each FK?

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

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

发布评论

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

评论(1

请恋爱 2024-09-11 00:56:30

我不知道是否有工具可以让你做到这一点。

您始终可以用[您最喜欢的脚本语言]编写脚本来执行此操作。

它的工作方式如下:(

注意。我假设每个表都是 InnoDB 并且您想要转换所有表。我还假设您的数据库中没有视图。如果您有视图,那么您必须发出 SHOW相反,仅处理表类型表明它不是视图的那些行,而且,这不会消除与外键关联的索引 - 如果您需要手动执行此部分。不再需要所有索引。另外,在执行任何操作之前备份数据库!尽管这是不言而喻的。)

  1. 创建一个空数组/列表/任何内容,$foreign_keys
  2. 问题 SHOW TABLES
  3. 对于显示的每个表:
    • 问题SHOW CREATE TABLE表名
    • /CONSTRAINT `(.+)` FOREIGN KEY/ 进行正则表达式搜索
    • 对于每场比赛,
      • 将同一行上的外键详细信息添加到数组$foreign_keys
      • 发出 DROP FOREIGN KEY 语句
  4. 对于每个表,发出 ALTER TABLE tablename ENGINE=NDB
  5. 对于数组中的每个条目 $foreign_keys,发出 < code>CREATE TRIGGER 语句

也许实际上有一些工具可以为您完成此操作,但另一方面,如果您不想手动执行此操作,这可能是您需要执行的操作。

I don't know if there are tools to let you do this.

You could always write a script in [your favourite scripting language] to do it.

It would work like:

(NB. I assume that every table is InnoDB and that you want to convert all of them. I also assume that there are no views in your db. If you have views then you have to issue SHOW FULL TABLES instead and treat only those rows for which the table type indicates that it is not a view. Also, this will not get rid of the indexes associated to foreign keys - you would need to do this part manually if you didn't want all of the indexes any more. Also, back up your database before you do anything! Although that goes without saying.)

  1. Create an empty array/list/whatever, $foreign_keys
  2. Issue SHOW TABLES
  3. For each table displayed:
    • Issue SHOW CREATE TABLE tablename
    • Do a regular expression search for /CONSTRAINT `(.+)` FOREIGN KEY/
    • For each match,
      • add the details of the foreign key on the same line to your array $foreign_keys;
      • issue a DROP FOREIGN KEY statement
  4. For each table, issue ALTER TABLE tablename ENGINE=NDB
  5. For each entry in your array $foreign_keys, issue a CREATE TRIGGER statement

Perhaps there actually are tools out there that will do it for you, but on the other hand this might be what you need to do if you don't want to do it manually.

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