[英]How to import a big database from Heroku to local mysql or sqlite3?
As per title I need to import, but PG backups is giving me strict Postgres SQL that doesn't work with MySQL, also with a non-specified encoding that I guess is UTF-16. 根据标题,我需要导入,但是PG备份为我提供了严格的Postgres SQL,该SQL无法与MySQL一起使用,并且还提供了我认为是UTF-16的非指定编码。 Using db:pull takes ages and errors before finishing.
使用db:pull会花费一些时间和错误,然后才能完成。 I'd appreciate any suggestion.
我将不胜感激任何建议。 Thanks.
谢谢。
Set up PostgreSQL locally, use PG backups to copy the data from Heroku to your local machine, then pg_restore
to import it into your new local PostgreSQL. 在本地设置PostgreSQL,使用PG备份将数据从Heroku复制到本地计算机,然后使用
pg_restore
导入到新的本地PostgreSQL。 Then you can copy it from PostgreSQL to MySQL or SQLite locally without having to worry about timeouts. 然后,您可以在本地将它从PostgreSQL复制到MySQL或SQLite,而不必担心超时。 Or, since you'd have a functional PostgreSQL installation after that, just start developing on top of PostgreSQL so that your development stack better matches your deployment stack;
或者,由于在那之后安装了功能正常的PostgreSQL,因此只需在PostgreSQL之上开始开发,以使您的开发堆栈更好地与您的部署堆栈匹配; developing and deploying on the same database is a good idea.
在同一个数据库上进行开发和部署是一个好主意。
You're probably getting binary dumps (ie pg_dump -Fc
) from Heroku, that would explain why the dump looks like some sort of UTF-16 nonsense. 您可能会从Heroku获得二进制转储(即
pg_dump -Fc
),这将解释为什么转储看起来像某种UTF-16废话。
You can use the pgbackups addon to export the database dump 您可以使用pgbackups 插件导出数据库转储
$ heroku addons:add pgbackups # To install the addon
$ curl -o latest.dump `heroku pgbackups:url` # To download a dump
Heroku has instructions on how to do this: https://devcenter.heroku.com/articles/heroku-postgres-import-export#restore-to-local-database , which boil down to: Heroku上有关于如何执行此操作的说明: https : //devcenter.heroku.com/articles/heroku-postgres-import-export#restore-to-local-database ,其归结为:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
where myuser
is the current user and mydb
is the current database. 其中
myuser
是当前用户,而mydb
是当前数据库。
If you're using Postgres.app , it's pretty trivial to copy your production database locally. 如果您使用Postgres.app ,则在本地复制生产数据库非常简单。 You can leave out
-U myuser
unless you have configured it otherwise, and create a database by running $ psql -h localhost
and then CREATE DATABASE your_database_name;
除非另行配置,否则可以不使用
-U myuser
,并通过运行$ psql -h localhost
然后CREATE DATABASE your_database_name;
(from the Postgres.app documentation . Then run the above command and you're set. (来自Postgres.app文档 。然后运行上面的命令,您已设置好。
Install the Heroku Backup tool: 安装Heroku Backup工具:
$ heroku addons:add pgbackups
Start using it: 开始使用它:
$ heroku pgbackups:capture
Download the remote db on Heroku (to your local machine) using curl: 使用curl将Heroku上的远程数据库下载到本地计算机上:
$ curl -o latest.dump 'heroku pg:backups public-url'
Load it*: 加载*:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U YOUR_USERNAME -d DATABASE_NAME latest.dump
That's it! 而已!
UPDATE: It is updated to the new interface 更新:已更新到新界面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.