直到将学习用的数据导入到PostgreSQL中为止(SQL超级入门)
前提条件 (Qian ti tiao jian)
macOS Catalina 10.15.6:Catalina操作系统的版本为10.15.6。
简述
这是关于在学习《从零开始理解SQL超入门》时,无法使用书中提供的PostgreSQL安装方法时所做记录的内容。
安装PostgreSQL
安装PostgreSQL
# インストール
$ brew install postgresql
设定DB的存储位置
$ vi ~/.bash_profile
export PGDATA=/usr/local/var/postgres
我会将上述内容添加到.bash_profile中。
启动PostgreSQL
# PostgreSQLの立ち上げ
$ brew services start postgresql
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
对于PostgreSQL数据库的操作
创建PostgreSQL用户
$ createuser ユーザー名 --interactive
Shall the new role be a superuser? (y/n)
# 新しく作成するユーザーをスーパーユーザーにするか聞かれるので y を選択する。
对于PostgreSQL的处理
# PostgreSQLにログイン
$ psql -U ユーザー名
postgres=#
# 学習用データの取り込み
postgres=# \i '~/Downloads/zerosql/import_mac.sql'
# 接続しているデータベースのテーブル一覧
postgres=# \d
# PostgreSQLからログアウト
postgres=# \q
停止PostgreSQL
# PostgreSQLの停止
$ brew services stop postgresql
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)