[英]Postgresql Database export to .sql file
I want to export my database as a.sql file.我想将我的数据库导出为 .sql 文件。 Can someone help me?
有人能帮我吗? The solutions I have found don't work.
我找到的解决方案不起作用。 A detailed description please.
请详细说明。 On Windows 7.
在 Windows 7.
pg_dump defaults to plain SQL export. pg_dump默认为纯 SQL 导出。 both data and structure.
数据和结构。
open command prompt and run pg_dump -U username -h localhost databasename >> sqlfile.sql
打开命令提示符并运行
pg_dump -U username -h localhost databasename >> sqlfile.sql
Above command is preferable as most of the times there will be an error which will be something like - ...FATAL: Peer authentication failed for user ...
上面的命令是可取的,因为大多数时候都会出现一个错误,类似于 -
...FATAL: Peer authentication failed for user ...
In windows, first, make sure the path is added in environment variables PATH在windows中,首先确保在环境变量PATH中添加了路径
C:\\Program Files\\PostgreSQL\\12\\bin
After a successful path adding restart cmd and type command路径添加成功后重启cmd并输入命令
pg_dump -U username -p portnumber -d dbname -W -f location
this command will export both schema and data
此命令将导出架构和数据
for only schema use -s in place of -W and for only data use -a.仅用于模式使用 -s 代替 -W,仅用于数据使用 -a。
replace each variable like username, portnumber, dbname and location according to your situation everything is case sensitive, make sure you insert everything correctly, and to import
根据您的情况替换每个变量,如用户名、端口号、dbname 和位置,一切都区分大小写,确保正确插入所有内容,然后导入
psql -h hostname -p port_number -U username -f your_file.sql databasename
make sure your db is created or creation query is present in .sql file确保您的数据库已创建或创建查询存在于 .sql 文件中
Go to your command line and run Go 到你的命令行并运行
pg_dump -U userName -h localhost -d databaseName > ~/Desktop/cmsdump.sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.