本章介绍了访问数据库的各种方法,假设无涯教程已经在上一章中创建了一个数据库,您可以使用以下两种方法之一选择数据库:
假设您已经启动了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无涯教程网
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕