POSTGRESQL启动和简单使用
最笨的方法,目前我也只会这一种。
进入PSQL的安装目录,在bin文件夹下启动终端,先用postgres用户登录。然后键入./pg_ctl -D /usr/local/pgsql/data -l logfile start即可启动。
建立名为test的数据库:./createdb test.
创建新表
先进入管理数据库模式 ./psql test
postgres@linux-eaho:/usr/local/pgsql/bin> ./psql test
Welcome to psql 8.3.3, the PostgreSQL interactive terminal.
Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit
test=#
用SQL语句建表
test=# CREATE TABLE weather (
test(# city varchar(80),
test(# temp_lo int, -- 最低气温
test(# temp_hi int, -- 最高气温
test(# prcp real, -- 降水量
test(# date date
test(# );
看到最后出现CREATE TABLE说明建表成功!
特别主义所有语句都以“;”结束!!!
用SQL语句插入数据
test=# INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');
INSERT 0 1
用标准的SQL语句即可实现数据库操作功能,还可以通过文本文档来操作。
test=#COPY weather FROM '/home/user/weather.txt';
查询一个表:
SELECT * FROM weather;