ubuntu中用命令创建数据库

本文档详细介绍了如何使用sudo权限切换到PostgreSQL账户、创建新的PostgreSQL登录账户及其密码设置,并通过三种不同方式恢复数据库的过程。此外还提供了创建空数据库、授予用户权限等实用步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# switch to postgres account
sudo su postgres
  
# create a new postgres login: jetty; and set the password to jetty
# since most of our database dump has jetty as the user
createuser -P -d -a -e jetty
#password jetty
 
# create a new postgres login: logintext;
# this is also due to database dump file; SHOULD HAVE DUMP DATABASE WITH -U option;
createuser -P -d -a -e logintext
# create a new empty database
# set the password to jetty (to be consistent with application setting - only for DEV/TESTING)
createdb test -O jetty
  
# grant permission to jetty
psql
#click Enter on keyboard
GRANT all on database test to jetty;
#click Enter on keyboard
\q
#click Enter on keyboard
 
# restore database option1
psql test </tmp/<dumpfile>
 
# restore database option2
psql -d test -t ~/tmp/<dumpfile>
 
# restore database option 3
# psql -d <database> U <username> -f <filename>
psql -d test -U logintest -f demo.test.s83.0.sql
 
# return to your own account
exit

 

转载于:https://www.cnblogs.com/cc-java/p/6474812.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值