【问题标题】:Import dump/sql file into my postgresql database on Linode将转储/sql 文件导入我在 Linode 上的 postgresql 数据库
【发布时间】:2014-07-16 22:59:22
【问题描述】:

我最近将我的 Ruby on Rails 4 应用程序从 Heroku 移到了 Linode。一切都已正确设置,但我需要用一个文件填充我的数据库,我们称之为movies.sql

我对 postgresql 命令和 VPS 不是很熟悉,所以很难完成。我将它上传到 Dropbox,因为我看到了许多可以使用 S3/Dropbox 的 SO 帖子。

我看到了类似这样的不同命令(不确定在我的情况下如何执行):

  1. psql -U postgres -d testdb -f /home/you/file.sql

  2. psql -f file.sql dbname

  3. psql -U username -d myDataBase -a -f myInsertFile

那么在我的情况下哪个是正确的,当我在 Linode 中进行 SSH 时如何运行?谢谢

【问题讨论】:

    标签: sql ruby-on-rails postgresql vps linode


    【解决方案1】:

    您需要将文件放到您的服务器上,或者您需要从终端使用不同的命令。

    如果你在本地有文件,你可以使用 psql 命令在不使用 sshing 的情况下恢复:

    psql -h <user@ip_address_of_server> -U <database_username> -d <name_of_the_database> -f local/path/to/your/file.sql
    

    否则,命令为:

    psql -U <database_username> -d <name_of_the_database> < remote/path/to/your/file.sql
    

    -U 设置数据库用户名,-h 设置主机,-d 设置数据库名称,-f 告诉您从文件恢复的命令。

    【讨论】:

    • 命令的第二个版本在文件名前缺少-f标志
    猜你喜欢
    • 1970-01-01
    • 2011-07-22
    • 2018-01-23
    • 2012-09-08
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 2019-10-05
    相关资源
    最近更新 更多