欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2021年01月04日 09:44:34   作者:㏑.格調(diào)ル  
這篇文章主要介紹了PostgreSQL用戶、數(shù)據(jù)庫及表的管理、操作與授權(quán)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

摘要

PostgreSQL的常用命令

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

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

登錄成功顯示如下:

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

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

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

3、用戶管理

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

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

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

5、表操作

/* 增加讓主鍵自增的權(quán)限 */
grant all on sequence tablename_keyname_seq to webuser;
 /* 重命名一個表 */
alter table [表名A] rename to [表名B]; 
/* 刪除一個表 */
drop table [表名]; 
/* 在已有的表里添加字段 */
alter table [表名] add column [字段名] [類型]; 
/* 刪除表中的字段 */
alter table [表名] drop column [字段名]; 
/* 重命名一個字段 */
alter table [表名] rename column [字段名A] to [字段名B]; 
/* 給一個字段設(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 [表名];
/* 查詢 */
SELECT * FROM dbname WHERE ...;
/* 創(chuàng)建表 */
create table (
  [字段名1] [類型1] primary key,
  [字段名2] [類型2],
  ......,
  [字段名n] [字段名n] )

6、退出

\q
quit

補(bǔ)充:postgresql 授權(quán)某個數(shù)據(jù)庫的權(quán)限給test 賬號 使該賬號 只能操作指定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 操作,在那個db環(huán)境執(zhí)行就授哪個db的權(quán)

刪除前撤銷

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

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

相關(guān)文章

最新評論