简体   繁体   English

使用psql将.sql文件导入postgres

[英]import .sql file into postgres using psql

Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
psql (10.6)
WARNING: Console code page (437) differs from Windows code page (1252)
     8-bit characters might not work correctly. See psql reference
     page "Notes for Windows users" for details.
Type "help" for help.



postgres=#  create database mydb;
CREATE DATABASE
postgres=#  psql -d mydb -f Telnet.sql;
ERROR:  syntax error at or near "psql"
LINE 1: psql -d mydb -f Telnet.sql;
    ^postgres=#

/*I am not able to figure out the error I have tried a number of other commands as well but I am not able to figure out the issue. / *我也无法找出错误,但我也尝试了许多其他命令,但无法找出问题。

You are already running psql so you can only execute SQL commands or psql specific commands 您已经在运行psql因此您只能执行SQL命令特定于psql的命令

To connect to the newly created database use the psql command \\c : 要连接到新创建的数据库,请使用psql命令\\c

postgres=# \c mydb

The prompt should then change to 然后提示应更改为

mydb=#

To run a SQL script from within psql use the psql command \\i 运行SQL脚本psql使用psql命令\\i

mydb=# \i Telnet.sql

Note that psql commands (those starting with \\ ) are not terminated with ; 请注意, psql命令(以\\开头的命令) ;终止; - that is only necessary for SQL commands. -只有SQL命令才需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM