使用自动增量从 MySQL 迁移到 Postgresql - 如何?
我正在考虑将我的 Web 应用程序从 MySQL 迁移到 Postgresql,但是我很难将现有的 MySQL 数据库转换为 Postgresql。
我尝试过:
- mysldump 以及
- 来自 EnterpriseDB 的 --兼容=postgresql 迁移向导 来自
- EMS 的 Postgresql 数据向导 来自
- DMSoft 的 DBConvert
并且上述程序都不能很好地转换我的数据库!
我看到一些 Perl 和 Python 脚本用于将 mysql 转换为 postgresql,但我不知道如何使用它们....(我安装了 ActivePerl,但不明白下一步应该做什么来运行该脚本! )
我一直使用自动增量字段(作为主键),而这些都被忽略了...我知道 Postgresql 以另一种方式(使用序列)进行自动增量,但是对于迁移来说这并不难软件来实现这一点,或者是吗?
有没有人在转换使用自动增量作为主键的 MySQL 数据库时运气更好?
I'm considering a MySQL to Postgresql migration for my web application, but I'm having a really hard time converting my existing MySQL database to Postgresql.
I tried :
- mysldump with --compatible=postgresql
- migration wizard from EnterpriseDB
- Postgresql Data Wizard from EMS
- DBConvert from DMSoft
and NONE of the above programs do a good job converting my database!
I saw some Perl and Python scripts for converting mysql to postgresql, but I can't figure out how to use them....(I installed ActivePerl and don't understand what I'm supposed to do next to run that script!)
I use Auto Increment fields (as a primary key) all the time, and these are just ignored... I understand that Postgresql does auto-increments in another way (with sequences), but it can't be THAT hard for MIGRATION software to implement that, or is it?
Did anybody have better luck converting a MySQL database with auto-increments as primary keys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道这可能不是您正在寻找的答案,但是:我不相信“自动”迁移工具。
使用创建数据库架构的现有 SQL 脚本,搜索并替换必要的数据类型(自动编号映射到
serial
,它会自动为您执行所有序列处理),删除所有“engine= " 然后针对 Postgres 运行新脚本。将旧数据库转储到平面文件中并将它们导入到目标中。
我已经用 MySQL 的示例数据库完成了几次这样的操作,而且确实不需要那么长时间。
可能只要尝试所有不同的“自动化”工具即可。
I know this is probably not the answer you are looking for, but: I don't believe in "automated" migration tools.
Take your existing SQL Scripts that create your database schema, do a search and replace for the necessary data types (autonumber maps to
serial
which does all the sequence handling automagically for you), remove all the "engine=" stuff and then run the new script against Postgres.Dump the old database into flat files and import them into the target.
I have done this several times with sample databases that were intended for MySQL and it really doesn't take that long.
Probably just as long as trying all the different "automated" tools.
为什么不使用 ETL 工具?你不必担心垃圾场或类似的事情。
我已经迁移到 PostgresSQL 和 MySQL,并且自动增量字段没有任何问题。
您只需要知道连接凭据即可。我个人使用 Pentaho(它是开源的)。
从 http://kettle.pentaho.org/ 下载 Pentaho ETL
解压并运行 Pentaho(使用 .bat 文件 Spoon) .bat)
创建新作业:
为源数据库(PostgreSQL)创建数据库连接 - 使用菜单:工具→向导→创建数据库连接(F3)为目标数据库(Mysql)创建数据库连接 - 使用上述技术。
运行向导:工具 → 向导 → 复制表 (Ctrl-F10)。
选择源(左侧对话框面板)和目标(左侧对话框面板)。单击“完成”。
将生成作业 - 运行作业。
如果您需要任何帮助,请告诉我。
Why not use an ETL Tool? you dont have to worry about dumps or stuff like that.
I have migrated to PostgresSQL and MySQL and have had no problems with the auto increment fields.
You just need to know the connection credentials and thats it. I personally use Pentaho ( it's open source ).
Download Pentaho ETL from http://kettle.pentaho.org/
Unzip and run Pentaho (using .bat file spoon.bat)
Create a new Job:
Create DB connection for source data base (PostgreSQL) - using menu: Tools→Wizard→Create DataBase Connection (F3) Create DB connection for destination data base (Mysql) - using technique described above.
Run the Wizard: Tools → Wizard → Copy Tables (Ctrl-F10).
Select source (left dialog panel), and destination (left dialog panel). Click Finish.
The Job will be generated - Run the job.
If you need any help let me know.
即使您熟悉所有“PostgreSQL 陷阱”,手动执行每一步也可能需要花费大量时间,尤其是当您的数据库“很大”时。
尝试一些其他脚本/工具。
Even when you familiar with all "PostgreSQL gotchas", doing every step by hand may take a lot of time, especially when your db is "big".
Try some other scripts/tools.
我知道这是一个老问题,但我刚刚从 MySQL 迁移到 Postgres 时遇到了同样的问题。在尝试了几种迁移工具之后,我找到了最好的一个,它将尽可能干净地迁移您的数据库结构,那就是 Pgloader https://github.com/dimitri/pgloader/ 它将负责将自动增量更改为 Postgres 序列,没有问题,而且速度超级快。
I know this is an old question but I just ran into the same problem migrating from MySQL to Postgres. After trying several migration tools out the very best one I could find, which will migrate your database structure as cleanly as possible, was Pgloader https://github.com/dimitri/pgloader/ it will take care of changing the Auto Increment to Postgres sequences no problem and it's super fast.