[转] Mac 下 PostgreSQL 的安装与使用
2016-03-22 22:12
274 查看
在 mac 下,可以利用 homebrew 直接安装 PostgreSQL:
稍等片刻,PostgreSQL 就安装完成。接下来就是初始数据库,在终端执行一下命令,初始配置 PostgreSQL:
上面指定 "/usr/local/var/postgres" 为 PostgreSQL 的配置数据存放目录,并且设置数据库数据编码是 utf8,更多配置信息可以 "initdb --help" 查看。
设成开机启动 PostgreSQL:
启动 PostgreSQL:
关闭 PostgreSQL:
创建一个 PostgreSQL 用户
上面的 username 是用户名,回车输入 2 次用户密码后即用户创建完成。更多用户创建信息可以 "createuser --help" 查看。
创建数据库
上面创建了一个名为 dbname 的数据库,并指定 username 为改数据库的拥有者(owner),数据库的编码(encoding)是 UTF8,参数 "-e" 是指把数据库执行操作的命令显示出来。
更多数据库创建信息可以 "createdb --help" 查看。
连接数据库
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/local/Cellar/postgresql/9.5.1/bin/pg_ctl -D /usr/local/var/postgres -l logfile start
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510
To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see:
http://www.postgresql.org/docs/9.5/static/upgrading.html
To migrate existing data from a previous minor version (9.0-9.4) of PosgresSQL, see:
http://www.postgresql.org/docs/9.5/static/pgupgrade.html
You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`.
Do not run `brew cleanup postgresql` until you have performed the migration.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
==> Summary
🍺 /usr/local/Cellar/postgresql/9.5.1: 3,118 files, 35M
XXXdeMacBook-Air:chat-room XXX$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "XXX".
This user must also own the server process.
The database cluster will be initialized with locale "zh_CN.UTF-8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
XXXdeMacBook-Air:chat-room XXX$
设成开机启动 PostgreSQL:
创建数据库
更多数据库创建信息可以 "createdb --help" 查看。
连接数据库
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/local/Cellar/postgresql/9.5.1/bin/pg_ctl -D /usr/local/var/postgres -l logfile start
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510
To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see:
http://www.postgresql.org/docs/9.5/static/upgrading.html
To migrate existing data from a previous minor version (9.0-9.4) of PosgresSQL, see:
http://www.postgresql.org/docs/9.5/static/pgupgrade.html
You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`.
Do not run `brew cleanup postgresql` until you have performed the migration.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
==> Summary
🍺 /usr/local/Cellar/postgresql/9.5.1: 3,118 files, 35M
XXXdeMacBook-Air:chat-room XXX$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "XXX".
This user must also own the server process.
The database cluster will be initialized with locale "zh_CN.UTF-8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
XXXdeMacBook-Air:chat-room XXX$
相关文章推荐
- [转]Ubuntu 12.04(32位)安装Oracle 11g(32位)全过程以及几乎所有问题的解决办法
- SQLite开源代码分析(一) main函数里面有多少东西
- Mysql在大型网站的应用架构演变
- mysql按ID排序(转)
- MySQL系列:用户及权限管理
- MySQL的create table as 与 like区别(转)
- oracle存储过程
- 安装了Visual Studio 2008自带的SQL Server 2005后,设置sa登录名
- 【mysql】数据库定时备份、数据恢复
- mysql中update select的值
- 十大监视SQL Server性能的计数器
- 关于oracle数据库(8)查询2
- mysql 转发自 WhyWin
- ADO.NET与Oracle(一):获取多行记录集
- mysql错误2002的解决办法 ERROR 2002 (HY000) mysql.sock(2)
- 第6天-sql简单数据实操
- SQL调优 - Hints指定索引 解决慢查询案例
- oracle 转 mysql 最新有效法(转)
- mysql 安装后报 ERROR 1045 (28000): Access denied for user 'root'@'localhost'
- 爱分享 » 30多条mysql数据库优化方法,千万级数据库记录查询轻松解决