服务器 频道

debian(sarge/stable)下的postgresql使用

  【IT168 服务器学院】在debian下安装东西是很简单, apt-get install postgresql 就都搞定了。

  安装完成后系统就启动了pg的服务,用netstat -ln 可以看到有5432端口等待连接,

  #su - postgres   #转成postgres系统用户
  $psql -d template1    #使用postgres用户进入数据库,连接template1数据库,这里不指定一个数据库的话,似乎不让进入数据库
  template1=#create user ftp with password ''YOURPASSWORD'';  #创建数据库用户ftp
  template1=#create database ftp with owner = ftp ;   #创建数据库ftp,属主名也是ftp
  template1=#\q
  $exit
  然后修改/etc/postgresql/pg_hba.conf文件,在下面这行
  # All IPv4 connections from localhost
  后门加入
  host    ftp     ftp     127.0.0.1       255.255.255.255         md5
  然后/etc/init.d/postgresql restart ;接着就可以使用
  $psql -h localhost -U ftp -W ftp
  来登录数据库了,象下面这样:

   psql -h localhost -U ftp -W ftp
  Password:
  Welcome to psql 7.4.7, the PostgreSQL interactive terminal.

  Type:  \copyright for distribution terms
         \h for help with SQL commands
         \? for help on internal slash commands
         \g or terminate with semicolon to execute query
         \q to quit

  ftp=>

  自己记下,这个东西折腾了我不少时间,手册上单单看用户认证那一部分似乎讲得并不多。

  tips:再记个东西,,手册上写的东西也不能完全相信:

  GRANT SELECT ON user TO ftp;我今天就是老是这个错误:ERROR:  syntax error at or near "user" at character 24最后发现:需要在user上加上双引号,即:GRANT SELECT ON "user" TO ftp;这样就成功的授权了。。。可怜折腾了我很久。
  

0
相关文章