1. 程式人生 > 其它 >資料庫 - postgresql的安裝和使用

資料庫 - postgresql的安裝和使用

技術標籤:資料庫資料庫

世界上並沒有完美的程式,但是我們並不因此而沮喪,因為寫程式就是一個不斷追求完美的過程。

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql13-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb sudo systemctl enable postgresql-13 sudo systemctl start postgresql-13 預設埠:5432 使用: 切換使用者:su postgres 進入:psql 顯示資料庫:\l 進入資料庫:\c [dbname] 建立資料庫:create database search; 刪除資料庫:drop database search; 建表: create table test( id varchar(32) primary key, name varchar
(255) ); 查看錶: 所有:\d 某個:\d [dbname] 刪除表格: drop table [dbname] 插入: insert into [tablename] (col1, col2, col3) values (v1, v2, v3); 查詢: select * from [tablename] limit: SELECT * FROM COMPANY LIMIT 3 OFFSET 2; 退出: \q 執行sql檔案生成資料表: ./psql -s xxx(xxx是你要執行的資料庫) -f /opt/xxx.sql 檢視編碼格式: \encoding

在這裡插入圖片描述