PostgreSQL安装与使用
PostgreSQL是开源的关系型数据库。
一、安装
1.1 Mac OS
Mac OS使用homebrew安装,在shell中输入brew search postgresql,得到以下输出:
==> Formulae
postgresql postgresql@11 postgresql@9.5
postgresql@10 ✔ postgresql@9.4 postgresql@9.6
==> Casks
navicat-for-postgresql选择需要安装的版本即可,@后为版本号,例如brew install postgresql@10安装PostgreSQL 10。
1.2 Linux
todo
1.3 Windows
todo
二、配置
2.1 Mac OS
如果安装的不是最新版本,则需要自行添加环境变量,以Postgre 10为例,需要添加以下环境变量:
export PATH="/usr/local/opt/postgresql@10/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/postgresql@10/lib"
export CPPFLAGS="-I/usr/local/opt/postgresql@10/include"
export PKG_CONFIG_PATH="/usr/local/opt/postgresql@10/lib/pkgconfig"在添加完成后,在shell中输入brew services,检查PostgreSQL是否运行,如果没有运行,需要运行PostgreSQL服务。以Postgre 10为例,shell输入brew services start postgresql@10即可启动服务。
2.2 Linux
todo
2.3 Windows
todo
三、使用
createdb <dbname>创建数据库;psql <dbname>进入数据库控制台;使用
\password <pass>为postgreSQL用户设置密码;使用
create user <username>创建数据库用户;创建表,用法如下:
reate table <tablename> ( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( 一个或多个列 ) );使用
grant all privileges on <tablename> to <username>将表的所有权限都赋给某用户。todo...
Last updated
Was this helpful?