PostgreSQL 到 MySQL 的转换 (Ruby on Rails)
是否有用于将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,这些迁移可能很棘手。我不知道有什么好的工具可以做到这一点。另请注意,这可能是一个很大的痛苦,并且您最终会放弃 PostgreSQL 为敏捷开发提供的许多优秀功能(例如事务 DDL)。话虽如此,解决方法如下:
在 MySQL 上重建架构。不要尝试转换架构文件本身。使用您现有的方法通过 MySQL 的语法生成新架构。
编写一个脚本,从 PostgreSQL 中提取数据并将其一次一行插入到 MySQL 中。 MySQL 存在一些线程锁定问题,这些问题会干扰批量加载、更新索引等。其中每个语句插入多行。为了决定表的顺序,我通常从 pg_dump 中列出表的顺序开始,尽管在 Rails 中您可以使用模型定义来代替。
检查您的索引策略以确保它们仍然适用。
总的来说,这些数据库非常不同。我不认为迁移会很容易。
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:
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.
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.
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.