• PostgressQL


    环境

    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

  • 相关阅读:
    URAL 1018 Binary Apple Tree
    URAL 1029 Ministry
    URAL 1039 Anniversary Party
    URAL 1078 Segments
    Codeforces 918D
    Codeforces 918C
    URAL 1495 One-two, One-two 2
    URAL 1244 Gentlemen
    URAL 1658 Sum of Digits
    URAL 1081 Binary Lexicographic Sequence
  • 原文地址:https://www.cnblogs.com/unixcs/p/13356708.html
Copyright © 2020-2023  润新知