数据库操作

最后更新于:2022-04-02 03:57:48

[TOC] ## 创建数据库 语法: ``` createdb [option...] [dbname [description]] ``` example: ``` CREATE DATABASE dbname; ``` ## 查看数据库 命令行 ``` postgres=# \l 名称 | 拥有者 | 字元编码 | 校对规则 | Ctype | 存取权限 -----------+----------+----------+--------------------------------+--------------------------------+----------------------- dd | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | demo | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | hello | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | postgres | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | template0 | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/postgres + | | | | | postgres=CTc/postgres ``` sql ``` > SELECT datname FROM pg_database; datname ----------- postgres demo template1 template0 hello dd ``` ## 进入 数据库 ``` postgres=# \c runoobdb ``` ## 删除数据库 语法 ``` DROP DATABASE [ IF EXISTS ] name ``` example ``` DROP DATABASE runoobdb; ```
';