a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 數據庫 > 文庫 > 正文

postgresql數據庫設置遠程登陸賬戶和密碼

2024-09-07 22:12:59
字體:
來源:轉載
供稿:網友
  本地登陸postgresql,建庫授權,設置密碼
 
  服務器本地登陸postgresql數據庫(默認是不需要密碼的)
 
  postgres@localhost ~]$ psql
 
  psql.bin (9.5.9)
 
  Type "help" for help.
 
  創建角色,并且給角色設置密碼:
 
  postgres=# create user testwjw with password 'Zykj@5&^%996';
 
  CREATE ROLE
 
  修改數據庫用戶和密碼:
 
  postgres=# alter user testwjw with password '558996';
 
  ALTER ROLE
 
  指定字符集創建數據庫testdb1,并且授權給testwjw
 
  postgres=# create database testdb1 with encoding='utf8' owner=testwjw;
 
  CREATE DATABASE
 
  授權:
 
  postgres=# grant all privileges on database testdb1 to testwjw;
 
  GRANT
 
  2.修改postgresql.conf文件中的端口和監聽主機:
 
  postsql默認安裝后是監聽本機127.0.0.1 默認端口是5432,是不能夠遠程登陸的,所以要修改監聽主機地址,同時修改默認的端口為:36985
 
  postgresql數據庫的配置文件是:postgresql.conf,所在位置是:postgresql初始化時所指定的data數據目錄下:
 
  [postgres@localhost ~]$ ll /data/postgresql/data/postgresql.conf
 
  -rw------- 1 postgres postgres 21305 Oct  3 11:18 /data/postgresql/data/postgresql.conf
 
  [postgres@localhost ~]$ egrep "listen_addresses|5432"/data/postgresql/data/postgresql.conf
 
  修改監聽主機為*,端口為:36985
 
  [postgres@localhost ~]$ egrep "listen_addresses|36985" /data/postgresql/data/postgresql.conf
 
  修改配置文件pg_hba.conf ,允許遠程ip訪問本地數據庫,以及設置服務器本地登陸postgresql數據庫要求輸入密碼才可以登陸
 
  [postgres@localhost ~]$ egrep "60.223.153.25|127.0.0.1" /data/postgresql/data/pg_hba.conf
 
  host    all             all             60.223.153.25/32            trust
 
  host    all             all             127.0.0.1/32            password
 
  #host    replication     postgres        127.0.0.1/32            trust
 
  允許  60.223.153.25ip訪問服務器postgresql數據庫
 
  psql -Utestwjw -dpostgres -p36985 -h 127.0.0.1 這樣訪問數據庫127.0.0.1數據庫必須輸入密碼才可以
 
  3.重啟postgresql服務生效:
 
  [postgres@localhost ~]$ pg_ctl -D /data/postgresql/data -l /data/postgresql/log/postgres.log restart
 
  waiting for server to shut down....LOG:  received fast shutdown request
 
  LOG:  aborting any active transactions
 
  LOG:  autovacuum launcher shutting down
 
  LOG:  shutting down
 
  LOG:  database system is shut down
 
   done
 
  server stopped
 
  server starting
 
  [postgres@localhost ~]$ netstat -lntup|grep postgres
 
  (Not all processes could be identified, non-owned process info
 
   will not be shown, you would have to be root to see it all.)
 
  tcp        0      0 0.0.0.0:36985               0.0.0.0:*                   LISTEN      6472/postgres  
 
  4.登陸數據庫:
 
  [postgres@localhost ~]$ psql
 
  psql.bin: could not connect to server: No such file or directory
 
  [postgres@localhost ~]$ psql -Utestwjw -dpostgres -p36985 -h 127.0.0.1
 
  Password for user testwjw:
 
  psql.bin: fe_sendauth: no password supplied
 
  [postgres@localhost ~]$ psql -Utestwjw -dpostgres -p36985 -h 127.0.0.1
 
  Password for user testwjw:
 
  psql.bin (9.5.9)
 
  Type "help" for help.
 
  postgres=> /q
 
  [postgres@localhost ~]$ psql -Utestwjw -dtestdb1 -p36985 -h 127.0.0.1
 
  Password for user testwjw:
 
  psql.bin (9.5.9)
 
  Type "help" for help.
 
  testdb1=> select * from t;
 
   id | nan | note  
 
  ----+-----+-------
 
    1 | t   | TRUE
 
    2 | f   | FALSE
 
    3 | t   | tRue
 
    4 | f   | fAlse
 
   11 |     | null
 
   11 |     | NULL
 
    7 | t   | 't'
 
    8 | f   | 'f'
 
    9 | t   | 'yes'
 
   10 | f   | '0'
 
  (10 rows)
 
  testdb1=>
 
  [postgres@localhost ~]$ psql -Utestwjw -dtestdb1 -p36985
 
  psql.bin (9.5.9)
 
  Type "help" for help.
 
  testdb1=> /q
 
  [postgres@localhost ~]$ psql -Utestwjw -dtestdb2 -p36985
 
  psql.bin (9.5.9)
 
  Type "help" for help.
 
  testdb2=> /q.

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品视频一区二区噜噜 | 欧美一区永久视频免费观看 | 欧美在线xxx | 国产一级视频 | 亚洲 中文 欧美 日韩 在线观看 | 黄色一级毛片 | 久久在线视频 | 求av网站| 国产精品自拍视频网站 | 中文字幕亚洲字幕一区二区 | 亚洲精品成人 | 精品一区二区国产 | 久久精品国产一区二区电影 | 欧美.www| 亚洲三级视频 | 羞羞在线观看视频免费观看hd | 欧美一区2区三区3区公司 | 久久精品视频免费看 | 久久99这里只有精品 | 国产一区二区三区四区五区 | 欧美一区不卡 | 成人一区二区av | 亚洲三级在线免费观看 | 国产欧美日韩综合精品 | 欧美精品在线观看 | 成人在线一区二区 | 免费观看一级特黄欧美大片 | 毛片毛片毛片毛片毛片毛片 | 一区二区三区在线 | 欧 | 成人精品国产 | 日本高清视频在线观看 | 中文字幕日韩一区二区不卡 | 国产一区观看 | 国产精品999| 91精品国产色综合久久不卡蜜臀 | 成人综合av| 日本高清视频网站www | 天天草夜夜操 | 亚洲v欧美 | 国产精品视频网站 | 91精品久久久久久久久 |