PostgreSQL - 选择数据库

PostgreSQL - 选择数据库 首页 / PostgreSQL入门教程 / PostgreSQL - 选择数据库

本章介绍了访问数据库的各种方法,假设无涯教程已经在上一章中创建了一个数据库,您可以使用以下两种方法之一选择数据库:

  • 数据库SQL提示
  • 操作系统命令提示符

数据库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=# 

操作系统命令

您可以在登录数据库时从命令提示符本身中选择数据库,以下是一个简单的示例-

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,并准备在testdb中执行命令。要从数据库退出,可以使用命令\q。

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/postgresql/postgresql-select-database.html

来源:LearnFk无涯教程网

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入剖析Kubernetes -〔张磊〕

透视HTTP协议 -〔罗剑锋(Chrono)〕

Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕

深入浅出云计算 -〔何恺铎〕

Kafka核心源码解读 -〔胡夕〕

如何读懂一首诗 -〔王天博〕

陈天 · Rust 编程第一课 -〔陈天〕

业务开发算法50讲 -〔黄清昊〕

去无方向的信 -〔小麥〕

好记忆不如烂笔头。留下您的足迹吧 :)