美文网首页
数据库编程

数据库编程

作者: mpyl | 来源:发表于2019-06-25 15:32 被阅读0次

    postgresql指令

    To migrate existing data from a previous major version of PostgreSQL run:

    brew postgresql-upgrade-database
    

    To have launchd start postgresql now and restart at login:

    brew services start postgresql
    

    Or, if you don't want/need a background service you can just run:

    pg_ctl -D /usr/local/var/postgres start
    

    psycopg2使用

    我是用的是Pyhton3自带的IDEL:

    >>> import psycopg2
    >>> cxn = psycopg2.connect(user='postgres')
    >>> cur = cxn.cursor()
    >>> cur.fetchall()
    >>> cur.execute('SELECT * FROM pg_database')
    >>> rows = cur.fetchall()
    >>> for i in rows:
        print(i)
    
    ('noduez', 10, 6, 'C', 'C', False, True, -1, 13381, '561', '1', 1663, None)
    ('template1', 10, 6, 'C', 'C', True, True, -1, 13381, '561', '1', 1663, '{=c/noduez,noduez=CTc/noduez}')
    ('template0', 10, 6, 'C', 'C', True, False, -1, 13381, '561', '1', 1663, '{=c/noduez,noduez=CTc/noduez}')
    ('postgres', 16385, 6, 'C', 'C', False, True, -1, 13381, '561', '1', 1663, '{=Tc/postgres,postgres=CTc/postgres}')
    >>> 
    

    sqlite使用

    >>> import sqlite3
    >>> cxn = sqlite3.connect('/Users/mac/sqlite_test/test.sqlite3')
    >>> cur = cxn.cursor()
    >>> cur.execute('create tables users(login varchar(8), userid integer)')
    >>> cur.execute('insert into users values("jhon", 100)')
    <sqlite3.Cursor object at 0x1148fe0a0>
    >>> cur.execute('insert into users values("jane", 110)')
    <sqlite3.Cursor object at 0x1148fe0a0>
    >>> cur.execute('select * from users')
     <sqlite3.Cursor object at 0x1148fe0a0>
    >>> for eachUser in cur.fetchall():
        print(eachUser)
    
    ('jhon', 100)
    ('jane', 110)
    >>> 
    

    相关文章

      网友评论

          本文标题:数据库编程

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