網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
1:docker安裝PostgreSQL
docker run --name postgresql -v /my/own/datadir:/var/lib/postgresql/data -e POSTGRES_PASSWORD=123456 -d -p 5432:5432 postgres:14.1
-
允許遠(yuǎn)程訪問(wèn)
進(jìn)入到postgresql容器docker exec -it postgresql bash
進(jìn)入postgresql配置文件
cd /var/lib/postgresql/data/
修改配置文件pg_hba.conf,最后一行新增如下內(nèi)容
host all all 0.0.0.0/0 trust
重啟postgresql?
docker restart postgresql
2:連接到psotgresql:
psql -h 127.0.0.1 -p 5432 -U usename -d database
說(shuō)明:
-h 主機(jī)名
-p 端口號(hào)
-U 用戶名
-d 數(shù)據(jù)庫(kù)
3:常用命令:
- 查看所有的數(shù)據(jù)庫(kù)列表
\l
- 使用?\c + 數(shù)據(jù)庫(kù)名?來(lái)進(jìn)入數(shù)據(jù)庫(kù)
\c test
- 查詢所有表列表,其中database為數(shù)據(jù)庫(kù)名稱
select * from pg_tables where tableowner='database';
- 查詢指定表的字段信息
SELECT c.relname 表名稱, A.attname AS 字段名稱, col_description(A.attrelid,A.attnum) AS 注釋, format_type ( A.atttypid, A.atttypmod ) AS 類(lèi)型, CASE WHEN A.attnotnull='f' THEN '否' ELSE '是' END AS 是否必填, a.attnum 序號(hào) FROM pg_class AS c, pg_attribute AS a WHERE A.attrelid = C.oid AND A.attnum > 0 and c.relname='tablename' ORDER BY c.relname,a.attnum;
- 退出連接
\q
4:增刪改查
-
創(chuàng)建數(shù)據(jù)庫(kù)
create database test; -
創(chuàng)建表student
create table student(
? id int,
? name varchar(32),
? birthday date,
? hgitht numeric(5,2)
); - 插入數(shù)據(jù)
insert into student values (1,'dym','2022-02-03 11:11:11',9.9); insert into student values (2,'張三','2022-02-13 11:11:11',9.3);
- 查詢數(shù)據(jù)
select * from student select * from student where id=1
- 修改數(shù)據(jù)
update student set hgitht =8.8 update student set hgitht =8.7 where id=2
- 刪除數(shù)據(jù)
delete from student where id=2
原文鏈接:https://blog.csdn.net/qq_36793589/article/details/122669595
相關(guān)推薦
- 2022-12-04 Android嵌套線性布局玩法坑解決方法_Android
- 2023-02-15 Python函數(shù)常見(jiàn)幾種return返回值類(lèi)型_python
- 2022-07-31 如何理解C++指針常量和常量指針_C 語(yǔ)言
- 2022-10-17 C++實(shí)現(xiàn)String類(lèi)的方法詳解_C 語(yǔ)言
- 2022-03-27 C++中兩種字符串定義方式和區(qū)別介紹_C 語(yǔ)言
- 2022-08-15 springboot實(shí)現(xiàn)動(dòng)態(tài)數(shù)據(jù)源切換
- 2023-05-30 Pandas.DataFrame行和列的轉(zhuǎn)置的實(shí)現(xiàn)_python
- 2022-11-08 PostgreSQL查看帶有綁定變量SQL的通用方法詳解_PostgreSQL
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支