发布于 2015-07-12 03:11:15 | 417 次阅读 | 评论: 0 | 来源: 网络整理

本章介绍访问数据库的各种方法。假设在我们的前面的章节中,我们已经创建了一个数据库。现在可以使用下面的方法选择数据库:

  • 数据库SQL提示符

  • OS(操作系统)命令提示符

数据库SQL提示

假设已经有PostgreSQL客户端打开,已经登陆下面的SQL提示:


postgres=#

你可以检查可用的数据库列表,利用l即反斜线el命令如下:


postgres-# l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | 
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 testdb    | postgres | UTF8     | C       | C     | 
(4 rows)

postgres-# 

现在键入下面的命令连接/选择所需的数据库,在这里我们将连接到testdb数据库:


postgres=# c testdb;
psql (9.2.4)
Type "help" for help.
You are now connected to database "testdb" as user "postgres".
testdb=# 

OS命令提示符

可以选择数据库从命令提示符,当登录到数据库。下面是一个简单的例子:


psql -h localhost -p 5432 -U postgress testdb
Password for user postgress: ****
psql (9.2.4)
Type "help" for help.
You are now connected to database "testdb" as user "postgres".
testdb=# 

现在登录到PostgreSQL的testdb内部准备执行命令。若想从数据库退出,可以使用命令q

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务