Loading

PostgressQL和pgadmin4

环境

ubuntu18.04 docker 中 pull postgres:10 images

连接

  • 进入容器内部

docker exec -it [mypostgres] /bin/bash

  • 查看postgres 版本
    pg_ctl -V

  • 在docker中连接数据库
    psql -U postgres -W # 使用密码登录

postgres

添加用户/密码

create user [name] with password '******';

修改用户密码

ALTER USER postgres WITH PASSWORD 'postgres'; #这里修改的是默认的postgres密码

添加数据库

create database [库名] owner [用户];

删除数据库

drop database [库名]

登陆

psql -U [name] -W

常用命令

  • 查看数据库
    \l
  • 连接数据库
    \c [库名]
  • 查看所有用户
    \du
  • 切换用户
    \c - [database]
  • 查看当前登录用户
    select * from current_user;
    or
    select user

postgress 表

增删改查

  • 查看表
    \d

  • 添加表

CREATE TABLE table_name(
   column1 datatype,
   column2 datatype,
   column3 datatype,
   .....
   columnN datatype,
   PRIMARY KEY( 一个或多个列 )
);
  • 删除表
    DROP TABLE [table1]; #删除单个表
    DROP TABLE [table1], [table2]; #删除多个表

python 连接 postgresql格式

import postgresql

  #('pq://用户名:密码@localhost:5432/数据库名')
db = postgresql.open('pq://jm:123@localhost:5432/test1')
ps=db.prepare("select * from a1")

print(ps())

ps.close()
db.close()

参考:
https://blog.csdn.net/smstong/article/details/17138355
https://my.oschina.net/ssssbook/blog/1800316

pgadmin4

连接

添加用户

创建数据库


posted @ 2020-07-21 18:26  Unixcs  阅读(374)  评论(0编辑  收藏  举报