• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

postgresql如何新建数据库

mysql 搞java代码 3年前 (2022-05-21) 30次浏览 已收录 0个评论

一、安装

可以参考postgresql官网安装教程:https://www.postgresql.org/download/linux/redhat/

Centos 6 安装postgresql 10

添加RPM:

-- <a href="https://www.gaodaima.com/tag/centos" title="查看更多关于centos的文章" target="_blank">centos</a> 6 安装 postgresql 10
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm
-- centos 7 安装 postgresql  10
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

www#gaodaima.com来源gao@dai!ma.com搞$代^码网搞代码

安装客户端:

yum install postgresql10

安装服务端:

yum install postgresql10-server

启动数据并初始化:

service postgresql-10 initdb
chkconfig postgresql-10 on
service postgresql-10 start

二、创建用户和数据库

# su - postgres -- 首先切换到postgres
-bash-4.1$ psql  -- 输入psql
psql (10.5)
Type "help" for help.
postgres=#

创建用户

postgres=# create user username with password '****';
CREATE ROLE
postgres=#

需要注意:

(1)要以英文分号结尾

(2)密码需要引号包裹

创建数据库

postgres=# create database dbtest owner username; -- 创建数据库指定所属者
CREATE DATABASE
postgres=#

将数据库得权限,全部赋给某个用户

postgres=# grant all on database dbtest to username; -- 将dbtest所有权限赋值给username
GRANT
postgres=#

三、数据库的导入导出

导入整个数据库

psql -U username databasename < /data/dum.sql -- 用户名和数据库名

Python学习网,大量的免费PostgreSQL入门教程,欢迎在线学习!

来源:搞代码网:原文地址:https://www.gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:postgresql如何新建数据库

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址