如何将 Rails 应用程序中的数据从 mySql 迁移到 SQLite

发布于 2024-08-11 19:14:41 字数 58 浏览 2 评论 0原文

如何将 Rails 应用程序中的数据从 mySql 迁移到 SQLite?

这可能吗?

How can I migrate my data from my rails app from mySql to SQLite?

Is this possible?

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

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

发布评论

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

评论(3

感悟人生的甜 2024-08-18 19:14:41

好问题!

过去,我必须将 Gb 数据库从 SQlite 迁移到 MySQL,再迁移到 PostgreSQl,反之亦然。我尝试了大量的实用程序、脚本和工具,但我发现成功迁移数据库的唯一方法是将数据导出到与数据库无关的架构中,然后导入数据。

这个插件拯救了我数千次的生命:yaml_db

Great question!

In the past I had to migrate Gb of databases from SQlite to MySQL to PostgreSQl and viceversa. I tried tons of utilities, scripts and tools but the only way I found to successfully migrate the database was to export the data into a database-free schema, then import the data.

This plugin saved my life thousands of times: yaml_db.

眼睛会笑 2024-08-18 19:14:41

如果您需要通过某种导出方法即时执行此操作,您只需打开几个数据库连接,一个到您的 mysql 数据库,一个到您的 sqlite 数据库,适当地映射字段,然后插入到您的 sqlite 实例。

如果您不必即时执行此操作,可以访问此页面

If you need to do it on the fly, via some sort of export method, you can just open a couple DB connections, one to your mysql db and one to your sqlite db, map the fields appropriately, and insert to your sqlite instance.

If you don't have to do it on the fly, there is this page.

梦在夏天 2024-08-18 19:14:41

如果您只是想将数据和模式从一个移动到另一个,这应该不会太难,但如果您使用的是 mySQL 的黑暗角落之一,事情可能会变得更加棘手。基本上,你应该将你的 mySql 数据库转储到某种文件中(有很多方法可以做到这一点,例如从命令行或从 phpmyAdmin 之类的东西),然后,如果没记错的话(自从我上次使用以来已经有一段时间了)做了这些),做这样的事情:

sqlite3 <database name> ".import <export file name>"

此外,有一个脚本可以在 sqlite 网站的此页面,因此您可能会看到它是否确实有效。

If you just want to move your data and schema from one to the other, this shouldn't be too hard, although if you are using one of the dark corners of mySQL, things might get hairier. Basically, you should dump your mySql database to some sort of file (there are a ton of ways to do this, for example from the command line or from something like phpmyAdmin) and then, if memory serves (it's been a while since I last did this stuff), do something like this:

sqlite3 <database name> ".import <export file name>"

Additionally, there is a script to automate this on the this page of the sqlite website, so you might see if it actually works.

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