您的位置:首页 > 数据库

Ubuntu server PostgreSQL安装以及基本操作

2016-09-10 15:45 561 查看
1. 安装:

   sudo apt-get install postgresql

2.登录postgresql

 sudo -u postgres psql  或者 su  postgres

3.创建数据库 

createdb  数据库名;

4.创建表:

如:

CREATE TABLE weather (

    city            varchar(80),

    temp_lo         int,           -- low temperature

    temp_hi         int,           -- high temperature

    prcp            real,          -- precipitation

    date            date

);

向表中添加行:

如:

NSERT INTO weather VALUES ('beijing', 46, 50, 0.25, '1994-11-27');

5. 访问数据库:

psql  数据库名

 

6.其他:

\l                         -- 查看有哪些数据库

\q                         -- 退出

\c   数据库名                 -- 从之前的库切换到 数据库名

\d  table_name             -- 查看表结构

\dt                        -- 查看有哪些表

\di                        -- 查看索引

\du                        -- 查看角色

OVER
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  postgresql