[英]Import dump/sql file into my postgresql database on Linode
I recently moved my Ruby on Rails 4 app from Heroku to Linode. 我最近将Ruby on Rails 4应用程序从Heroku移到了Linode。 Everything has been setup correctly, but I need to populate my database with a file, lets call it movies.sql 一切都已正确设置,但我需要用一个文件填充数据库,让我们将其称为movie.sql
I am not very familiar with postgresql command and VPS, so having trouble getting this done. 我对postgresql命令和VPS不太熟悉,因此很难做到这一点。 I uploaded it to Dropbox since I saw many SO posts that you can use S3/Dropbox. 我将其上传到Dropbox,因为看到了许多可以使用S3 / Dropbox的SO帖子。
I saw different commands like this (unsure how to go about it in my situation): 我看到了这样的不同命令(不确定如何处理):
psql -U postgres -d testdb -f /home/you/file.sql
psql -f file.sql dbname
psql -U username -d myDataBase -a -f myInsertFile
So which is the correct one in my situation and how to run when I SSH in Linode? 那么在我的情况下哪种才是正确的,以及在Linode中进行SSH时如何运行? Thanks 谢谢
You'll need to get the file onto your server or you'll need to use a different command from your terminal. 您需要将文件放到服务器上,或者需要从终端使用其他命令。
If you have the file locally, you can restore without sshing in using the psql command: 如果您在本地拥有该文件,则可以不使用psql命令进行恢复而进行还原:
psql -h <user@ip_address_of_server> -U <database_username> -d <name_of_the_database> -f local/path/to/your/file.sql
Otherwise, the command is: 否则,命令为:
psql -U <database_username> -d <name_of_the_database> < remote/path/to/your/file.sql
-U
sets the db username, -h
sets the host, -d
sets the name of the database, and -f
tells the command you're restoring from a file. -U
设置db用户名, -h
设置主机, -d
设置数据库的名称, -f
告诉您要从文件还原的命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.