加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgreSQL入门01-安装

发布时间:2020-12-13 17:47:31 所属栏目:百科 来源:网络整理
导读:postgreSQL跟mysql,oracle,DB2,Sybase一样,是一种数据库。 oracle的命令行工具是sqlplus; kingbase的命令行工具是isql postgreSQL的命令行工具是psql mysql的命令行工具是mysql postgreSQL是免费开源的数据库软件。 linux下的安装和使用 1,安装 安装之

postgreSQL跟mysql,oracle,DB2,Sybase一样,是一种数据库。

oracle的命令行工具是sqlplus;
kingbase的命令行工具是isql
postgreSQL的命令行工具是psql
mysql的命令行工具是mysql

postgreSQL是免费开源的数据库软件。
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 installpostgresql-libs-8.1.23-1.el5_7.3.i386.rpm

yum installpostgresql-server-8.1.23-1.el5_7.3.i386.rpm

yum installpostgresql-libs-8.1.23-1.el5_7.3.i386.rpm

或者rpm -ivhpostgresql-8.1.23-1.el5_7.3.i386.rpm

rpm -ivhpostgresql-server-8.1.23-1.el5_7.3.i386.rpm

rpm -ivhpostgresql-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,连接和使用
然后启动服务:servicepostgresql 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 FilesPostgreSQL9.1bin)加到path环境变量中,然后打开cmd命令行。
(2)连接和使用
输入psql huangwei postgres前者是数据库名称后者是用户名
如下:
C:Documents and SettingsAdministrator> 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';

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读