数据库的命令窗口
在PostgreSQL 的命令窗口中,我们可以命令提示符后面输入 SQL 语句:
postgres=#
使用 \l 用于查看已经存在的数据库:
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
runoobdb | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
接下来我们可以使用 \c + 数据库名 来进入数据库:
postgres=# \c runoobdb
You are now connected to database "runoobdb" as user "postgres".
runoobdb=#
在系统的命令行查看,之后可以在连接数据库后面添加数据库名来选择数据库:
$ psql -h localhost -p 5432 -U postgress runoobdb
Password for user postgress: ****
psql (11.3)
Type "help" for help.
You are now connected to database "runoobdb" as user "postgres".
runoobdb=#
pgAdmin 工具
pgAdmin 工具更简单了,直接点击数据库选择就好了,还可以查看一些数据库额外的信息:
PostgreSQL 删除数据库可以用以下三种方式:
1、使用 DROP DATABASE SQL 语句来删除。
2、使用 dropdb 命令来删除。
3、使用 pgAdmin 工具。
注意:删除数据库要谨慎操作,一旦删除,所有信息都会消失。建议定期备份镜像文件,以免发生错误删除引起的数据丢失。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。