PostgreSQL 到 MySQL 的转换 (Ruby on Rails)

发布于 2024-08-29 20:09:39 字数 65 浏览 2 评论 0原文

是否有用于将 PostgreSQL 数据库转换为 MySQL 数据库的 Ruby 脚本?我搜索了很多网站都没有结果。

Is there any Ruby script for converting a PostgreSQL database to a MySQL database? I have searched many sites to no avail.

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

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

发布评论

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

评论(1

柒夜笙歌凉 2024-09-05 20:09:39

老实说,这些迁移可能很棘手。我不知道有什么好的工具可以做到这一点。另请注意,这可能是一个很大的痛苦,并且您最终会放弃 PostgreSQL 为敏捷开发提供的许多优秀功能(例如事务 DDL)。话虽如此,解决方法如下:

  1. 在 MySQL 上重建架构。不要尝试转换架构文件本身。使用您现有的方法通过 MySQL 的语法生成新架构。

  2. 编写一个脚本,从 PostgreSQL 中提取数据并将其一次一行插入到 MySQL 中。 MySQL 存在一些线程锁定问题,这些问题会干扰批量加载、更新索引等。其中每个语句插入多行。为了决定表的顺序,我通常从 pg_dump 中列出表的顺序开始,尽管在 Rails 中您可以使用模型定义来代替。

  3. 检查您的索引策略以确保它们仍然适用。

总的来说,这些数据库非常不同。我不认为迁移会很容易。

To be honest these migrations can be tricky. I don't know that there are any good tools to do it. Also note that this can be a major pain, and you end up giving up on a lot of nice features that PostgreSQL has for agile development (like transactional DDL). This being said, here's the way to go about it:

  1. Rebuild your schema on MySQL. Do not try to convert schema files per se. Use your existing approaches to generate a new schema using MySQL's syntax.

  2. Write a script which pulls data from PostgreSQL and inserts it one row at a time into MySQL. MySQL has some thread locking problems that interfere with bulk loads, updating indexes, etc,. where multiple rows are inserted per statement. For deciding the table order, what I have usually started with is the order the tables are listed in pg_dump, though in Rails you may be able to use your model definition instead.

  3. Review your indexing strategies to make sure they are still applicable.

On the whole these dbs are very different. I would not expect that the migration will be easy.

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