xiaui520 发表于 2016-11-19 09:21:17

cygwin下使用postgreSQL

  1.安装

运行Cygwin的安装程序setup.exe,选中以下组件

Database/

|--postgresql

进行安装。

2.设置

环境变量的设置

在~/.bashrc中添加如下内容:

export CYGWIN=server

export PGDATA=/usr/local/pgsql/data

export PGCLIENTENCODING=EUC_CN

在~/.bash_profile中添加如下内容:

PATH="/usr/sbin:/sbin:${PATH}"

export PATH

运行

$ source ~/.bashrc

$ source ~/.bash_profile

让刚才的设置生效。

cygserver的设置

运行

$ cygserver-config

看到提示yes/no的时候,输入yes,回车。

启动cygserver

$ cygserver &

初始化数据库

$ initdb --no-locale --encoding=EUC_CN

3.启动

$ pg_ctl start

之前须确认cygserver是否启动了。

4.创建用户和数据库

运行

$ createuser -d -a root   (创建用户root)

$ createdb -U root -O root test   (创建数据库,用户和所有者都是root)

5.使用数据库

$ psql test root

如正常,即出现postgreSQL的提示符.

test=# \?   (即出现postgreSQL的常用命令)                                                                                      
 
test=# create table people (
test-#       first_name varchar,
test-#       last_name varchar
  test-# );                                                                                                                                       

 
test=# insert into people values ('wang','wu');
 
test=# select * from people;
 
first_name  | last_name
--------------+---------------
 wang         | wu
 
  test=# \q  (退出PostgreSQL提示符的命令)                                                                                       

6.停止

$ pg_ctl stop

即停止PostgreSQL数据库服务。

7.补充

安装过程比较有可能出问题的是initdb的时候。如果出错,请运行

$ rm -rf /usr/local/pgsql/data

删除数据路径,解决问题后再运行initdb。


psql语法
\h   查看SQL语法
\?   查看psql语法
  \du 查看所有的用户
  \l    查看所有的数据库
\z   查看当前所有的数据表,视图
  自我感觉有点像mysql,呵呵自已的看法而已.
页: [1]
查看完整版本: cygwin下使用postgreSQL