centos7安裝postgresql配置鏈結

2021-10-07 09:50:59 字數 2367 閱讀 6448

(親測可用)

安裝centos7

安裝postgresql 安裝postgresql命令此處需要切換至root : su - root

命令路徑鏈結

命令:yum install

yum install postgresql10-server

/usr/pgsql-10/bin/postgresql-10-setup initdb

systemctl enable postgresql-10

systemctl start postgresql-10

3。修改postgresql使用者密碼(安裝完之後,會自動生成乙個postgres使用者)

切換postgres使用者:su - postgres

登入資料庫:psql -u postgres

可能會出現以下錯誤:(重啟psql再進入,systemctl restart postgresql-10.service)

更新密碼:alter user postgres with encrypted password 『abc123』;//自定義密碼

4.配置遠端訪問:vi /var/lib/pgsql/9.4/data/postgresql.conf

找到listen_addresses = 『localhost』 ,將 localhost 改為 * port = 5432(這兩句前面的#需要去掉,#表示注釋)

vi /var/lib/pgsql/10/data/pg_hba.conf

如果允許本地專案訪問,將local、ipv4、ipv6的peer、ident改為trust

並在ipv4增加一行:

host all all 0.0.0.0/0 md5

重啟服務:systemctl restart postgresql-10.service

防火牆設定:firewall-cmd --add-service=postgresql --permanentfirewall-cmd --reload

5.相關命令

systemctl restart postgresql-10.service #重啟服務systemctl enable postgresql-10.service #設定開機自啟systemctl start postgresql-10.service #開啟服務

systemctl status postgresql-10.service #檢視服務狀態資料庫相關操作:

\q #退出postgresql\l #檢視所有資料庫

\dt  #檢視資料庫表

\d test  #檢視表結構

\c dbname  #切換資料庫

\i /patha/***.sql #執行某個sql檔案

\exit 退出使用者

1,控制台常用命令:

\h:檢視sql命令的解釋,比如\h select。

?:檢視psql命令列表。

\l:列出所有資料庫。

\c [database_name]:連線其他資料庫。

\d:列出當前資料庫的所有**。

\d [table_name]:列出某一張**的結構。

\du:列出所有使用者。

\e:開啟文字編輯器。

\conninfo:列出當前資料庫和連線的資訊。

2,資料庫基本操作:

#建立新錶

create table user_tbl(name varchar(20), signup_date date);

#插入資料

insert into user_tbl(name, signup_date) values(『張三』, 『2013-12-22』);

#選擇記錄

select * from user_tbl;

#更新資料

update user_tbl set name = 『李四』 where name = 『張三』; #刪除記錄

delete from user_tbl where name = 『李四』 ;

#新增字段

alter table user_tbl add email varchar(40);

#更新結構

alter table user_tbl alter column signup_date set not null;

#更名字段

alter table user_tbl rename column signup_date to signup;

#刪除字段

alter table user_tbl drop column email;

#**更名

alter table user_tbl rename to backup_tbl;

#刪除**

drop table if exists backup_tbl;

centos7 安裝centos桌面

一 輸入命令 yum groupinstall gnome desktop graphical administration tools 二 設定系統啟動等級。systemctl get default 獲取當前系統執行形式,會顯示multi user.target 命令列終端 或者 graphic...

centos7安裝nginx(yum安裝)

感興趣的可以檢視用壓縮包安裝的過程 1 通過檢視當前linux核心以及版本號進行獲取nginx的rpm安裝源適配。uname a2 獲取nginx相關的rpm源 防止版本號不對應產生的各種問題 rpm uvh3 yum安裝nginx yum install nginx等待安裝完成。1 安裝完成後,n...

CentOS7安裝docker(yum安裝)

1.中文文件 2.檢視linux版本 cat etc redhat release3.是否聯網 這裡yun安裝,不聯網gg 4.解除安裝舊版本 sudo yum remove docker docker client docker client latest docker common docker...