15. 15
CLI で PostgreSQL にアクセスする方法
▌psql コンソールのセットアップ
▌データベースに接続
15
$ yum install postgresql
CentOS 7.2
$ psql -h 192.168.0.100 -U postgres
Password for user postgres:
psql (9.2.15, server 9.4.7)
WARNING: psql version 9.2, server version 9.4.
Some psql features might not work.
Type "help" for help.
postgres=#
CentOS 7.2
-h のあとに接続先のホスト名を、
-U のあとにログインするユーザ(ここでは postgres)を指定
16. 16
データベースの作成
▌データベースの作成と確認
16
postgres=# create database mydata;
postgres-# ¥l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
mydata | devdata | UTF8 | C | C |
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
(4 rows)
postgres-#
CentOS 7.2
「create database mydata;」は「mydata」という名称のデータベースを作成。
「¥l」はデータベース一覧を表示するコマンド