• Postgresql常用命令


    以下为刚接触postgresql常需要的数据库命令:

    1. 登录数据库                          psql -U 用户名 -W 数据库名      -h ip -p 端口  最后这两个参数可以有可以无,看使用情况
    2. 查看所有的用户                       select * from pg_user;
    3. 查看当前数据库下有的表                  select * from pg_tables;                 或者/dt
    4. 查看用户表权限                       select * from information_schema.table_privileges where grantee='用户名';
    5. 查看用户具有权限的表                   select * from information_schema.usage_privileges where grantee='用户名';
    6. 查看某表的具体字段情况                  d +表名
    7. 查看数据库下所有的schema                 dr
    8. 创建数据库                           createdb  数据库名称
    9. 删除数据库                           dropdb   数据库名
    10. 创建用户                            create user /role with password  '你要设置的密码'; 
                                        这里user和role的区别是: 用user默认创建的用户具有登录权限,用role无登录权限后面需要授权
    11. 修改密码                            ALTER ROLE 用户名 WITH PASSWORD '*'; 
    12. admin用户,INSERT INTO authors,提示没有表权限
    1. admindb=> INSERT INTO authors (name) VALUES ('Mo Yan'); 
    2. ERROR: permission denied for table authors
    1. postgres用户,授予表权限
    1. admindb=# GRANT ALL PRIVILEGES ON TABLE authors TO admin; 
    2. GRANT
    1. admin用户,INSERT INTO authors,提示没有sequence权限
    1. admindb=> INSERT INTO authors (name) VALUES ('Mo Yan'); 
    2. ERROR: permission denied for sequence authors_id_seq
    1. postgres用户,授予sequence权限
    1. admindb=# GRANT ALL PRIVILEGES ON SEQUENCE authors_id_seq TO admin; GRANT
  • 相关阅读:
    第一课:数据库介绍篇
    爬虫day03 cast
    python excel
    爬虫 cast_day05_多进程_多线程_协程_selenium的使用
    进程_线程_协程回顾!
    进程_线程_协程回顾 2!
    day 06 爬虫
    看正月点灯笼老师的笔记 —动态规划2.1
    动态规划——放苹果

  • 原文地址:https://www.cnblogs.com/lifei01/p/12436183.html
Copyright © 2020-2023  润新知