postgreSQL |安装(Ubuntu、macos)、配置
说明 待补充 PostgreSQL安装参考 《一天学会PostgreSQL应用开发与管理》阿里云社区 PostgreSQL角色和权限 PostgreSQL中database、table、schema三者关系 PostgreSQL模式(架构) PostgreSQL中的schema macos安装 一、安装1、安装使用如下命令,会自动安装最新版,这里为9.5 sudo apt-get install postgresql 安装完成后,默认会: (1)创建名为"postgres"的Linux用户 (2)创建名为"postgres"、不带密码的默认数据库账号作为数据库管理员 (3)创建名为"postgres"的表 安装完成后的一些默认信息如下: config /etc/postgresql/9.5/main 2、生成的默认数据库3、psql命令安装完后会有PostgreSQL的客户端psql,通过sudo-u postgres psql进入,提示符变成:postgres=# 在这里可用执行SQL语句和psql的基本命令。可用的基本命令如下: password:设置密码 q:退出 h:查看SQL命令的解释,比如h select。 ?:查看psql命令列表。 l:--list databases c [database_name]:连接其他数据库。 d:列出当前数据库的所有表格。 d [table_name]:列出某一张表格的结构。 du:列出所有用户。 e:打开文本编辑器。 conninfo:列出当前数据库和连接的信息。 dn --list schemas 二、配置三、macos安装brew install postgresql 遇到异常(没有授权) fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied error: could not lock config file .git/config: Permission denied ==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.6.3.sierra.bot Already downloaded: /Users/admin/Library/Caches/Homebrew/postgresql-9.6.3.sierra.bottle.tar.gz ==> Pouring postgresql-9.6.3.sierra.bottle.tar.gz Error: The `brew link` step did not complete successfully The formula built,but is not symlinked into /usr/local Could not symlink share/doc/postgresql /usr/local/share/doc is not writable. 授权、重新安装 sudo chown -R admin /usr/local/ brew reinstall postgresql 初始化数据库 initdb /usr/local/var/postgres -E utf8 开机启动 ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 启动数据库 pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start 创建用户 createuser username -P --两次密码 创建DB createdb dbname -O username -E UTF8 -e 登陆 psql -U username -d dynamo -h localhost -p (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |