濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > PostgreSQL用戶(hù)、數(shù)據(jù)庫(kù)及表的管理、操作與授權(quán)方式

PostgreSQL用戶(hù)、數(shù)據(jù)庫(kù)及表的管理、操作與授權(quán)方式

熱門(mén)標(biāo)簽:辦公外呼電話(huà)系統(tǒng) 外呼調(diào)研系統(tǒng) 漯河外呼電話(huà)系統(tǒng) 打電話(huà)智能電銷(xiāo)機(jī)器人授權(quán) 海豐有多少商家沒(méi)有地圖標(biāo)注 合肥公司外呼系統(tǒng)運(yùn)營(yíng)商 重慶自動(dòng)外呼系統(tǒng)定制 美容工作室地圖標(biāo)注 地圖標(biāo)注和圖片名稱(chēng)的區(qū)別

摘要

PostgreSQL的常用命令

1、登錄數(shù)據(jù)庫(kù)

/* 切換到數(shù)據(jù)庫(kù)用戶(hù) */
su - postgres
/* 登錄 */
psql

登錄成功顯示如下:

bash-4.2$ psql
psql (9.3.17)
Type "help" for help.
postgres=> 

2、切換數(shù)據(jù)庫(kù)

/* 登錄指定數(shù)據(jù)庫(kù) */
psql -U user -d dbname
/* 列舉數(shù)據(jù)庫(kù) */
\l
/* 切換數(shù)據(jù)庫(kù) */
\c dbname

3、用戶(hù)管理

/* 創(chuàng)建用戶(hù) */
CREATE ROLE rolename;
CREATE USER username WITH PASSWORD '*****';
/* 顯示所有用戶(hù) */
\du
/* 修改用戶(hù)權(quán)限 */
ALTER ROLE username WITH privileges;
/* 賦給用戶(hù)表的所有權(quán)限 */
GRANT ALL ON tablename TO user; 
/* 賦給用戶(hù)數(shù)據(jù)庫(kù)的所有權(quán)限 */
GRANT ALL PRIVILEGES ON DATABASE dbname TO dbuser;
/* 撤銷(xiāo)用戶(hù)權(quán)限 */
REVOKE privileges ON tablename FROM user;
/* 撤銷(xiāo)用戶(hù)權(quán)限 */

4、數(shù)據(jù)庫(kù)操作

/* 創(chuàng)建數(shù)據(jù)庫(kù) */
create database dbname; 
/* 刪除數(shù)據(jù)庫(kù) */
drop database dbname; 

5、表操作

/* 增加讓主鍵自增的權(quán)限 */
grant all on sequence tablename_keyname_seq to webuser;
 /* 重命名一個(gè)表 */
alter table [表名A] rename to [表名B]; 
/* 刪除一個(gè)表 */
drop table [表名]; 
/* 在已有的表里添加字段 */
alter table [表名] add column [字段名] [類(lèi)型]; 
/* 刪除表中的字段 */
alter table [表名] drop column [字段名]; 
/* 重命名一個(gè)字段 */
alter table [表名] rename column [字段名A] to [字段名B]; 
/* 給一個(gè)字段設(shè)置缺省值 */
alter table [表名] alter column [字段名] set default [新的默認(rèn)值];
/* 去除缺省值 */
alter table [表名] alter column [字段名] drop default; 
/* 插入數(shù)據(jù) */
insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......); 
/* 修改數(shù)據(jù) */
update [表名] set [目標(biāo)字段名]=[目標(biāo)值] where ...; 
/* 刪除數(shù)據(jù) */
delete from [表名] where ...; 
/* 刪除表 */
delete from [表名];
/* 查詢(xún) */
SELECT * FROM dbname WHERE ...;
/* 創(chuàng)建表 */
create table (
  [字段名1] [類(lèi)型1] primary key,
  [字段名2] [類(lèi)型2],
  ......,
  [字段名n] [字段名n] )

6、退出

\q
quit

補(bǔ)充:postgresql 授權(quán)某個(gè)數(shù)據(jù)庫(kù)的權(quán)限給test 賬號(hào) 使該賬號(hào) 只能操作指定DB 不能操作其他DB

alter user test set default_transaction_read_only=on;
grant all on database crm_db to test;
grant select on all tables in schema public to test;   // 起作用的是這句 要進(jìn)入crm_db 操作,在那個(gè)db環(huán)境執(zhí)行就授哪個(gè)db的權(quán)

刪除前撤銷(xiāo)

revoke all on database crm_prod_myl from test;
revoke select on all tables in schema public from test;

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • Postgresql 賦予用戶(hù)權(quán)限和撤銷(xiāo)權(quán)限的實(shí)例
  • postgresql限制某個(gè)用戶(hù)僅連接某一個(gè)數(shù)據(jù)庫(kù)的操作
  • PostgreSQL 實(shí)現(xiàn)快速刪除一個(gè)用戶(hù)
  • 在postgresql數(shù)據(jù)庫(kù)中創(chuàng)建只讀用戶(hù)的操作
  • 查看postgresql數(shù)據(jù)庫(kù)用戶(hù)系統(tǒng)權(quán)限、對(duì)象權(quán)限的方法
  • postgresql 查看當(dāng)前用戶(hù)名的實(shí)現(xiàn)

標(biāo)簽:珠海 來(lái)賓 株洲 衡陽(yáng) 錦州 烏海 晉城 蚌埠

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PostgreSQL用戶(hù)、數(shù)據(jù)庫(kù)及表的管理、操作與授權(quán)方式》,本文關(guān)鍵詞  PostgreSQL,用戶(hù),數(shù)據(jù)庫(kù),及,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PostgreSQL用戶(hù)、數(shù)據(jù)庫(kù)及表的管理、操作與授權(quán)方式》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于PostgreSQL用戶(hù)、數(shù)據(jù)庫(kù)及表的管理、操作與授權(quán)方式的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    临江市| 大渡口区| 黔江区| 新郑市| 乌鲁木齐县| 汶川县| 阿图什市| 新竹市| 镇原县| 庆阳市| 醴陵市| 防城港市| 荆州市| 虹口区| 孟连| 广丰县| 乌拉特中旗| 沙洋县| 都安| 织金县| 灵宝市| 日土县| 迁西县| 长泰县| 疏勒县| 永平县| 江安县| 和硕县| 灵丘县| 辽阳县| 邵东县| 正蓝旗| 贺兰县| 沙湾县| 民权县| 寿阳县| 邓州市| 腾冲县| 镇宁| 巴马| 河北区|