mac安装postgresql

安装

1. 源代码编译安装也可以或者利用homebrew这些源代码管理包也可以
2. 安装好后,运行如下命令创建一个数据库
$ initdb /usr/local/var/postgres -E utf8
最后会输出如下信息:
Success. You can now start the database server using:

postgres -D /usr/local/var/postgres

or

pg_ctl -D /usr/local/var/postgres -l logfile start  

3.利用上述命令启动postgresql server。

常见命令行工具

  1. 连接数据库(需要另开一个终端):
    psql -U user -d dataname
  2. 列举数据库:
    SELECT datname FROM pg_database;\l
  3. 切换数据库:
    \c dbname
  4. 列举表: 
    \dt
  5. 查看表结构:
    \d tbname
  6. sql语句语法是通用的。    
  7. 更多帮助信息请输入:
    help
  8. 退出数据库:
    \q 

详细的安装信息参见:http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/  

 

猜你喜欢

转载自meigesir.iteye.com/blog/1930786