psql -U pgsql -d postgresreassign owned by r_read to pgsql;drop owned by r_read;dropuserifexists r_read;reassign owned by r_read_write to pgsql;drop owned by r_read_write;dropuserifexists r_read_write;reassign owned by u01 to pgsql;drop owned by u01;dropuserifexists u01;reassign owned by u02 to pgsql;drop owned by u02;dropuserifexists u02;dropdatabaseifexists test;
权限实例
createdatabase test template=template0 encoding='UTF8' locale='C';revokecreateonschemapublicfrompublic;\c test pgsql
droptableifexists t1;droptableifexists t2;createtable t1(id int, name varchar);createtable t2(id int, name varchar);insertinto t1 values(1,'a'),(2,'b');insertinto t2 values(1,'a'),(2,'b');select*from t1;select*from t2;-- 创建只读角色create role r_read;grantselectonalltablesinschemapublicto r_read;ALTERDEFAULTPRIVILEGESINSCHEMApublicgrantselectontablesto r_read;-- 创建读写角色create role r_read_write;grantselect,insert,update,deleteonalltablesinschemapublicto r_read_write;ALTERDEFAULTPRIVILEGESINSCHEMApublicgrantselect,insert,update,deleteontablesto r_read_write;-- 创建只读用户createuser u01;grant r_read to u01;-- 对于未来创建的表也授予 select 权限-- 创建读写用户createuser u02;grant r_read_write to u02;\c test u01
select*from t1;select*from t2;insertinto t1 values(3,'c');-- 报错才是正常的\c test u02
select*from t1;select*from t2;insertinto t1 values(3,'c');insertinto t2 values(3,'c');\c test pgsql
createtable t3(id int);insertinto t3 values(1);\c test u01
select*from t3;insertinto t3 values(2);\c test u02
select*from t3;insertinto t3 values(2);-- 可以正常插入# 实操```sql[pgsql@mysql01~]$ psql -U pgsql -d postgres
psql (14.5)Type"help"for help.postgres=# create database test template=template0 encoding='UTF8' locale='C';CREATEDATABASE
postgres=# revoke create on schema public from public;REVOKE
postgres=#
postgres=# \c test pgsql
You are now connected todatabase"test"asuser"pgsql".
test=# create table t1(id int, name varchar);CREATETABLE
test=# create table t2(id int, name varchar);CREATETABLE
test=# insert into t1 values(1,'a'),(2,'b');[pgsql@mysql01~]$ psql -U pgsql -d postgres -c "drop database test;"DROPDATABASE[pgsql@mysql01~]$ psql -U pgsql -d postgres
psql (14.5)
postgres=# drop database if exists test;DROPDATABASE
postgres=# create database test template=template0 encoding='UTF8' locale='C';CREATEDATABASE
postgres=# revoke create on schema public from public;REVOKE
postgres=# \c test pgsql
You are now connected todatabase"test"asuser"pgsql".
test=# drop table if exists t1;
NOTICE: table"t1" does not exist, skipping
DROPTABLE
test=# drop table if exists t2;
NOTICE: table"t2" does not exist, skipping
DROPTABLE
test=#
test=# create table t1(id int, name varchar);CREATETABLE
test=# create table t2(id int, name varchar);CREATETABLE
test=# insert into t1 values(1,'a'),(2,'b');INSERT02
test=# insert into t2 values(1,'a'),(2,'b');INSERT02
test=#
test=# select * from t1;id | name
----+------1| a2| b
(2rows)test=# select * from t2;id | name
----+------1| a2| b
(2rows)test=#
test=# -- 创建只读角色
test=# create role r_read;CREATE ROLE
test=# grant select on all tables in schema public to r_read;GRANT
test=# ALTER DEFAULT PRIVILEGES IN SCHEMA public grant select on tables to r_read;ALTERDEFAULTPRIVILEGES
test=# create role r_read_write;CREATE ROLE
test=# grant select, insert,update,delete on all tables in schema public to r_read_write;GRANT
test=# ALTER DEFAULT PRIVILEGES IN SCHEMA public grant select, insert, update, delete on tables to r_read_write;ALTERDEFAULTPRIVILEGES
test=# create user u01; CREATE ROLE
test=# grant r_read to u01;GRANT ROLE
test=#
test=# create user u02; CREATE ROLE
test=# grant r_read_write to u02;GRANT ROLE
test=# \c test u01
You are now connected todatabase"test"asuser"u01".
test=>select*from t1;id | name
----+------1| a2| b
(2rows)test=>select*from t2;id | name
----+------1| a2| b
(2rows)test=>insertinto t1 values(3,'c');-- 报错才是正常的
ERROR: permission denied fortable t1
test=> \c test u02
You are now connected todatabase"test"asuser"u02".
test=>select*from t1;id | name
----+------1| a2| b
(2rows)test=>select*from t2;id | name
----+------1| a2| b
(2rows)test=>insertinto t1 values(3,'c');INSERT01
test=>insertinto t2 values(3,'c');INSERT01
test=>
test=> \c test pgsql
You are now connected todatabase"test"asuser"pgsql".
test=# create table t3(id int);CREATETABLE
test=# insert into t3 values(1);INSERT01
test=#
test=# \c test u01
You are now connected todatabase"test"asuser"u01".
test=>select*from t3;id
----1(1row)test=>insertinto t3 values(2);
ERROR: permission denied fortable t3
test=> \c test u02
You are now connected todatabase"test"asuser"u02".
test=>select*from t3;id
----1(1row)test=>insertinto t3 values(2);INSERT01
test=>
文档:MySQL :: MySQL 5.7 Reference Manual :: 12.7 Date and Time Functions
以下为案例,更多内容可查看文档 返回当前日期: CURDATE() 返回当前时间: CURTIME() 返回当前日期和时间: NOW() 返回年份&a…
在安装好LNMP运行环境基础上,将codeigniter4文件夹移动到/var/nginx/html根目录下,浏览器地址栏输入IP/codeigniter/pulbic
一直提示:
Cache unable to write to "/var/nginx/html/codeigniter/writable/cache/".
找了好久&…