postgreSQL入门01-安装
? postgreSQL跟mysql,oracle,DB2,Sybase一樣,是一種數據庫。
oracle的命令行工具是sqlplus; kingbase的命令行工具是isql postgreSQL的命令行工具是psql mysql的命令行工具是mysqlpostgreSQL是免費開源的數據庫軟件。 linux下的安裝和使用 1,安裝 安裝之前最好創建一個postgres用戶,命令如下: groupadd postgres useradd postgres –g postgres?
然后修改密碼 passwd postgres 需要在linux下安裝如下三個包:
postgresql-8.1.23-1.el5_7.3.i386.rpm(postgreSQL客戶端)
?
postgresql-server-8.1.23-1.el5_7.3.i386.rpm(postgreSQL服務器)
?
postgresql-libs-8.1.23-1.el5_7.3.i386.rpm
安裝命令如下:
yum install?postgresql-libs-8.1.23-1.el5_7.3.i386.rpm
yum install??postgresql-server-8.1.23-1.el5_7.3.i386.rpm
yum install??postgresql-libs-8.1.23-1.el5_7.3.i386.rpm
或者rpm -ivh?postgresql-8.1.23-1.el5_7.3.i386.rpm
rpm -ivh??postgresql-server-8.1.23-1.el5_7.3.i386.rpm?
rpm -ivh??postgresql-libs-8.1.23-1.el5_7.3.i386.rpm
?
安裝完成之后使用chkconfig命令查看postgreSQL服務器運行情況:
?
[root@localhost awk-study]# chkconfig --list|grep postgres
postgresql ? ? ?0:關閉 ?1:關閉 ?2:關閉 ?3:關閉 ?4:關閉 ?5:關閉 ?6:關閉
2,連接和使用 然后啟動服務:service?postgresql start postgresql?服務啟動之后,就可以連接postgresql服務器了,那么如何連接呢? 在linux 終端中 (1)切換用戶:?su - postgres (2)運行psql -d postgres postgres 參數說明: -d 是指定數據庫名 如下: [root@localhost ~]# su - postgres -bash-3.2$ psql -d?postgres?postgres(前者是數據庫名稱,后者是用戶名) Welcome to psql 8.1.23, 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 然后就可以進行各種操作了,如創建一個簡單的數據表: postgres=# \c 你現在是以用戶 "postgres" 的身份聯接到數據庫 "postgres". postgres=#?create table student (id int ,name char(20)); CREATE TABLE windows下的安裝和使用 (1)安裝 安裝包可以在http://www.postgresql.org/download/下載。 下載結果為:postgresql-9.1.2-1-windows.exe 安裝之后,把安裝路徑下的bin目錄(例如C:\Program Files\PostgreSQL\9.1\bin)加到path環境變量中,然后打開cmd命令行。 (2)連接和使用 輸入psql?huangwei?postgres(前者是數據庫名稱,后者是用戶名) 如下: C:\Documents and Settings\Administrator>psql huangwei postgres psql (9.1.1) 輸入 "help" 來獲取幫助信息. huangwei=#?help 您正在使用psql, 這是一種用于訪問PostgreSQL的命令行界面 鍵入: \copyright 顯示發行條款 \h 顯示 SQL 命令的說明 \? 顯示 pgsql 命令的說明 \g 或者以分號(;)結尾以執行查詢 \q 退出 然后就可以進行sql操作了,如創建表: huangwei=#?create table t1(id int ,name char(30)); CREATE TABLE 如何退出psql 呢? huangwei=#?\q 基本使用: (1)查看當前模式下的所有表 范例:查看模式public下的所有表:select tablename from pg_tables where schemaname='public';
(2)創建用戶:
create user hw with password 'root' SUPERUSER CREATEDB CREATEROLE REPLICATION
?? VALID UNTIL 'infinity';
轉載于:https://blog.51cto.com/huangkunlun520/792054
總結
以上是生活随笔為你收集整理的postgreSQL入门01-安装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式学习笔记 1.介绍
- 下一篇: 残疾人无障碍设施工程改造送上门 900户