1.本地登陸postgresql,建庫(kù)授權(quán),設(shè)置密碼
成都創(chuàng)新互聯(lián)公司基于成都重慶香港及美國(guó)等地區(qū)分布式IDC機(jī)房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動(dòng)大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)服務(wù)器托管報(bào)價(jià),主機(jī)托管價(jià)格性價(jià)比高,為金融證券行業(yè)四川雅安服務(wù)器托管,ai人工智能服務(wù)器托管提供bgp線路100M獨(dú)享,G口帶寬及機(jī)柜租用的專業(yè)成都idc公司。
服務(wù)器本地登陸postgresql數(shù)據(jù)庫(kù)(默認(rèn)是不需要密碼的)
postgres@localhost ~]$ psql
psql.bin (9.5.9)
Type "help" for help.
創(chuàng)建角色,并且給角色設(shè)置密碼:
postgres=# create user testwjw with password 'Zykj@5&^%996';
CREATE ROLE
修改數(shù)據(jù)庫(kù)用戶和密碼:
postgres=# alter user testwjw with password '558996';
ALTER ROLE
指定字符集創(chuàng)建數(shù)據(jù)庫(kù)testdb1,并且授權(quán)給testwjw
postgres=# create database testdb1 with encoding='utf8' owner=testwjw;
CREATE DATABASE
授權(quán):
postgres=# grant all privileges on database testdb1 to testwjw;
GRANT
2.修改postgresql.conf文件中的端口和監(jiān)聽(tīng)主機(jī):
postsql默認(rèn)安裝后是監(jiān)聽(tīng)本機(jī)127.0.0.1 默認(rèn)端口是5432,是不能夠遠(yuǎn)程登陸的,所以要修改監(jiān)聽(tīng)主機(jī)地址,同時(shí)修改默認(rèn)的端口為:36985
postgresql數(shù)據(jù)庫(kù)的配置文件是:postgresql.conf,所在位置是:postgresql初始化時(shí)所指定的data數(shù)據(jù)目錄下:
[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
listen_addresses = 'localhost'# what IP address(es) to listen on;
port = 5432# (change requires restart)
修改監(jiān)聽(tīng)主機(jī)為*,端口為:36985
[postgres@localhost ~]$ egrep "listen_addresses|36985" /data/postgresql/data/postgresql.conf
listen_addresses = '*'# what IP address(es) to listen on;
port = 36985# (change requires restart)
修改配置文件pg_hba.conf ,允許遠(yuǎn)程ip訪問(wèn)本地?cái)?shù)據(jù)庫(kù),以及設(shè)置服務(wù)器本地登陸postgresql數(shù)據(jù)庫(kù)要求輸入密碼才可以登陸
[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訪問(wèn)服務(wù)器postgresql數(shù)據(jù)庫(kù)
psql -Utestwjw -dpostgres -p36985 -h 127.0.0.1 這樣訪問(wèn)數(shù)據(jù)庫(kù)127.0.0.1數(shù)據(jù)庫(kù)必須輸入密碼才可以
3.重啟postgresql服務(wù)生效:
[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.登陸數(shù)據(jù)庫(kù):
[postgres@localhost ~]$ psql
psql.bin: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
[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
網(wǎng)站名稱:postgresql數(shù)據(jù)庫(kù)設(shè)置遠(yuǎn)程登陸賬戶和密碼
URL標(biāo)題:http://jinyejixie.com/article8/ghdcop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、網(wǎng)頁(yè)設(shè)計(jì)公司、移動(dòng)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、關(guān)鍵詞優(yōu)化、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)