本文共 2436 字,大约阅读时间需要 8 分钟。
每个用户(USER)下可以有几个数据库(DATABASE),在使用某个数据库(DATABASE)时,先选择某个数据库(DATABASE),在数据库(DATABASE)里,可以对表(TABLE)进行操作。选择某个数据库在进行表操作,实现了数据库(DATABASE)和表(TABLE)的关联 。可以对 表进行增,删,改,查等操作。
sudo -u postgres psql
postgres=# CREATE DATABASE testdb1;CREATE DATABASEpostgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres testdb1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | (4 rows)
postgres=# \c testdb1You are now connected to database "testdb1" as user "postgres".testdb1=# lstestdb1-# \d
testdb1=# CREATE TABLE user_tbl(name VARCHAR(20),signnup_date DATE);CREATE TABLE
# 查询数据中的表testdb1=# \d List of relations Schema | Name | Type | Owner --------+----------+-------+---------- public | user_tbl | table | postgres(1 row)## 查询user_tbl表结构testdb1=# \d user_tbl Table "public.user_tbl" Column | Type | Collation | Nullable | Default --------------+-----------------------+-----------+----------+--------- name | character varying(20) | | | signnup_date | date | | |
## 向table中插入值testdb1=# INSERT INTO user_tbl(name,signnup_date) VALUES('zhangshan','2013-12-22');INSERT 0 1## 从table中查询值testdb1=# SELECT * FROM user_tbl; name | signnup_date -----------+-------------- zhangshan | 2013-12-22(1 row)
#修改用户密码postgres=# ALTER USER postgres PASSWORD 'fw123456';ALTER ROLE## 查看用户以及密码postgres=# select rolname,rolpassword from pg_authid; rolname | rolpassword ----------------------+------------------------------------- pg_monitor | pg_read_all_settings | pg_read_all_stats | pg_stat_scan_tables | pg_signal_backend | postgres | md59100df23a6ea8414560183285b3f5936(6 rows)
转载地址:http://fafab.baihongyu.com/