美文网首页
postgresql 基本用法 01

postgresql 基本用法 01

作者: fanchuang | 来源:发表于2019-01-15 01:24 被阅读0次

1. 安装暂时省略。

# 1. 根据各种提示信息安装。。。
Ubuntu includes PostgreSQL by default. 真是 晴天霹雳!
# 2. 查看服务开启情况。
 sudo service postgresql # 查看各种有效的命令
 sudo service postgresql start [stop, restart, reload, status]
3. 安装pqadmin (直接在软件中心搜一下)

2.进入

1. sudo -i -u postgres 或者 sudo su postgres
# 这样就以root 作为用户进入了。-i, login, -u , user

2.createdb testpython  # 创建一个数据库
3. psql testpython  # 进入psql 命令交互模式,并且选择刚刚创建的数据库。
4.\du   所有的用户信息
5.\dd   显示当前使用的这个数据库的信息
6.\l     显示所有的数据库。
7.\q    退出
8. CREATE USER u-name WITH PASSWARD 'somepassword'; # 创建用户
9. ALTER USER u-name WITH SUPER USER; 给新用户超级用户权限
10. DROP USER u-name;

3. python3连接postgresql 测试

# /usr/bin/python3
import psycopg2

try:
    # 注意这里各个参数之间是没有逗号的,只是一个空格而已。
    con_info = "dbname='testpython' user='mm' host='localhost'" + \
        "password='my-password'"

    conn = psycopg2.connect(con_info)
    cursor = conn.cursor()
    cursor.execute("""CREATE TABLE penny (name char(40));""")
    cursor.execute("""SELECT * FROM penny""")
    rows = cursor.fetchall()
    print(rows) # [] 成功了!!!
except Exception as e:
    print("Oh, no, failed!")
    print(e)

相关文章

  • postgresql 基本用法 01

    1. 安装暂时省略。 2.进入 3. python3连接postgresql 测试

  • PostgreSQL基本用法

    前言 PostgreSQL是一个开源的、对象关系型数据库管理系统(ORDBMS)。本文旨在介绍PostgreSQL...

  • PostgreSQL基本用法

    启动postgresqlsudo service postgresql start为了操作数据库,我们通常需要先登...

  • PostgreSQL基本用法

    前言 PostgreSQL[https://so.csdn.net/so/search?q=PostgreSQL&...

  • Psycopg 2.7 无责任翻译

    Psycopg - PostgreSQL database adapter for Python 基本模块用法 P...

  • postgresql编码问题

    基本使用参考 https://www.yiibai.com/postgresql/postgresql-inser...

  • Postgresql窗口函数(二)

    在上一篇里,主要窗口函数的基本用法。 在这一篇中,我们来看看postgresql除了聚合函数之外还支持哪些窗口函数...

  • day04- 查找和替换

    1、基本用法 01、查找 ctrl+f 02、替换 ctrl+h 2、进阶用法 01、查找整个工作薄的储君老师 范...

  • PostgreSQL的用法

    图灵完备 PostgreSQL是图灵完备的, 也就是说这货能编程 帮助命令 version 数据库 显示执行时间 ...

  • Postgresql与MySQL的区别

    在学习具体的Postgresql用法之前,我们来思考一下Postgresql与目前最常用的关系型数据库MySQL的...

网友评论

      本文标题:postgresql 基本用法 01

      本文链接:https://www.haomeiwen.com/subject/iszsdqtx.html