个人视频网站源码wordpress 关闭更新警告
个人视频网站源码,wordpress 关闭更新警告,郑州关键词优化费用,wordpress阻止访问第一部分案例总结概要
1.1 User概念
在SQL标准中#xff0c;User#xff08;用户#xff09;是指能够连接到数据库并执行操作的实体#xff0c;通常对应一个个体或应用程序。每个用户拥有唯一的标识符#xff08;如用户名#xff09;和认证机制#xff08;如密码#x…第一部分案例总结概要1.1 User概念在SQL标准中User用户是指能够连接到数据库并执行操作的实体通常对应一个个体或应用程序。每个用户拥有唯一的标识符如用户名和认证机制如密码。User在数据库集簇指由同一个数据库实例中的多个逻辑数据库的集合中是共享的。即只要用户有相应的权限就可以访问到数据库实例中的所有数据库。与User相关的还是一个role角色的术语其是一组权限的抽象集合用于简化权限管理。角色可以分配给用户或其他角色支持权限的层次化继承。但在不同的数据库中其实现也是有差异的。比如在PG系数据库中包括opengauss\gaussdb这两者是同一概念两者通过是否具有LOGIN权限来区分。有LOGIN权限的就是用户否则则是角色。也正因如此命令CREATE USER是命令 CREATE ROLE的一个别名。两者唯一的区别是 CREATE USER中LOGIN 被作为默认值而NOLOGIN是 CREATE ROLE的默认值而在Oracle数据库中这两者是严格区分的用户是用户角色是角色其更接近SQL标准中的定义。1.2 Schema概念在数据库中SCHEMA模式 是一个逻辑容器用于组织和管理数据库对象如表、视图、函数、索引等。它定义了数据库对象的命名空间和权限边界。SCHEMA是属于特定数据库的它不能在不同的数据库中共享。同样在不同的数据库中SCHEMA的实现也是不同的。比如在PG数据库中有专门的创建SCHEMA的命令create schema一个用户可以有专属的SCHEMA也可以没有而共用名为PUBLIC的SCHEMA。甚至一个用户还可以有多个SCHEMA。而在Oracle数据库中并无创建SCHEMA的命令。当创建用户时会自动创建出一个同名的SCHEMA。在Oracle库中一个用户有且只有一个对应的SCHEMA。而在GaussDB和OpenGauss中则是前述两者的混合在GaussDB和OpenGauss中创建用户时会自动创建出一个同名的SCHEMA。这一点类似Oracle。但是它又类似PG数据库可以创建新的SCHEMA允许一个用户有多个SCHEMA。1.3 需求背景及描述正因为上述的这些差异当我们面临希望一个用户可以在另一个用户所属的SCHEMA中创建表的需求时实现的方法就有了不同。下面三章我们将通过实例演示分别在Oracle、PG和GaussDB库操作的过程以及其行为表现。具体的需求如下1、 在数据库中创建两个用户user1和user2并各自拥有相应的同名SCHEMA。2、 实现user1可以在schema user2中创建表。第二部分 Oracle库中操作和表现2.1 创建用户和SCHEMA由于Oracle库中并无创建schema的命令而是在创建用户时自动创建同名的schema。所以并不需要单独创建schema。创建过程如下[oraclelocalhost~]$ sqlplus / as sysdba SQL*Plus:Release 11.2.0.4.0 Production on Wed May 7 08:57:45 2025 Copyright(c)1982,2013,Oracle. All rights reserved. Connected to an idle instance. SQL startup ORACLE instance started. Total System Global Area 3206836224 bytes Fixed Size 2257520 bytes Variable Size 536874384 bytes Database Buffers 2650800128 bytes Redo Buffers 16904192 bytes Database mounted. Database opened. SQL create user user1 identified by user1;User created. SQL grant connect,resource to user1;Grant succeeded. SQL create user user2 identified by user2;User created. SQL grant connect,resource to user2;Grant succeeded.2.2 授权前建表测试尝试分别使用用户USER1和USER2在各自的SCHEMA中创建表。过程如下SQL conn user1/user1 Connected. SQL create table user1_tab1(id number);Table created. SQL conn user2/user2 Connected. SQL create table user2_tab1(id number);Table created.再尝试使用用户user1在user2中创建表过程如下SQL conn user1/user1 Connected. SQL create table user2.user1_tab2(id number);create table user2.user1_tab2(id number)* ERROR at line 1:ORA-01031:insufficient privileges如上所示报权限不足。2.3 为用户USER1授权为用户USER1授予create any table的系统权限。过程如下SQL conn / as sysdba Connected. SQL grant create any table to user1;Grant succeeded.然后再测试使用用户user1在user2中创建表过程如下SQL conn user1/user1 Connected. SQL create table user2.user1_tab2(id number);Table created. SQL2.4 查询相关表的OWNER信息查询前述创建表的OWNER信息结果如下SQL select owner,table_name from dba_tables where table_name in(USER1_TAB1,USER2_TAB1);OWNER TABLE_NAME ------------------------------ ------------------------------ USER1 USER1_TAB1 USER2 USER2_TAB1 SQL如上所示可以看到各表的OWNER与该表的创建者是一致的。即谁创建的OWNER就是谁。第三部分 PG库中的操作和表现PG库的版本为12.2。3.1 创建用户和SCHEMA创建过程如下[postgreslocalhost~]$ psql -d mydb psql(12.2)Typehelpfor help. mydb# \conninfo You are connected to databasemydbas userpostgresvia socket in/tmpat port1921. mydb# create user user1 passworduser11234;CREATE ROLE mydb# create user user2 passworduser21234;CREATE ROLE如上所示我们在mydb库中创建了两个用户user1和user2。但此时查询库中的schema可以发现并没有同名的schema。如下所示mydb# \dn List of schemas Name | Owner ------------------ public | postgres(1 row)我们手工创建与用户同名的SCHEMA如下所示mydb# create schema user1 authorization user1;CREATE SCHEMA mydb# create schema user2 authorization user2;CREATE SCHEMA mydb# \dn List of schemas Name | Owner | Access privileges | Description ------------------------------------------------------------------ public | postgres | postgresUC/postgres | standard public schema | | UC/postgres | | | sqm_monitorU/postgres | user1 | user1 | | user2 | user2 | |(3 rows)如上所示我们为用户user1创建了同名的schemauser1为用户user2 创建了同名的schemauser2。3.2 授权前建表测试尝试分别使用用户USER1和USER2在各自的SCHEMA中创建表。过程如下[postgreslocalhost~]$ psql -d mydb -U user1 psql(12.2)Typehelpfor help. mydb \conninfo You are connected to databasemydbas useruser1via socket in/tmpat port1921. mydb mydb mydb create table user1_tab1(id int);CREATE TABLE mydb mydb \q [postgreslocalhost~]$ psql -d mydb -U user2 psql(12.2)Typehelpfor help. mydb \conninfo You are connected to databasemydbas useruser2via socket in/tmpat port1921. mydb mydb create table user2_tab1(id int);CREATE TABLE mydb mydb再尝试使用用户user1在user2中创建表过程如下[postgreslocalhost~]$ psql -d mydb -U user1 psql(12.2)Typehelpfor help. mydb create table user2.user1_tab2(id int);ERROR:permission denied for schema user2 LINE 1:create table user2.user1_tab2(id int);^ mydb如上所示报权限不足。3.3 为用户USER1授权为用户USER1授予create on schema user2的权限注在pg中并无create any table的系统权限存在。过程如下[postgreslocalhost~]$ psql -d mydb psql(12.2)Typehelpfor help. mydb# \conninfo You are connected to databasemydbas userpostgresvia socket in/tmpat port1921. mydb# grant create on schema user2 to user1;GRANT mydb# \q然后再测试使用用户user1在user2中创建表过程如下[postgreslocalhost~]$ psql -d mydb -U user1 psql(12.2)Typehelpfor help. mydb \conninfo You are connected to databasemydbas useruser1via socket in/tmpat port1921. mydb mydb create table user2.user1_tab2(id int);CREATE TABLE mydb3.4 查询相关表的OWNER信息查询前述创建表的OWNER信息结果如下[postgreslocalhost~]$ psql -d mydb -U user1 psql(12.2)Typehelpfor help. mydb \dt user1_tab2 Didnotfind any relation nameduser1_tab2. mydb mydb \dt user2.user1_tab2;List of relations Schema | Name | Type | Owner | Size | Description -------------------------------------------------------- user2 | user1_tab2 | table | user1 | 0 bytes |(1 row)如上所示我们可以看到user1在schema user2中创建的表其owner仍然是user1。查看两个用户在各自SCHEMA中创建的表user1_tab1和user2_tab1的owner信息结果如下所示mydb \dt user1.user1_tab1 List of relations Schema | Name | Type | Owner | Size | Description -------------------------------------------------------- user1 | user1_tab1 | table | user1 | 0 bytes |(1 row)mydb \dt user2.user2_tab1 List of relations Schema | Name | Type | Owner | Size | Description -------------------------------------------------------- user2 | user2_tab1 | table | user2 | 0 bytes |(1 row)如上所示可以看到各表的OWNER与该表的创建者是一致的。即谁创建的OWNER就是谁。该行为与Oracle中的表现是相同的。第四部分 GaussDB库中的操作和表现4.1 创建用户和SCHEMA创建过程如下[gaussdblocalhost~]$ gsql -d testdb -r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb# create user user1 passworduser11234;CREATE ROLE testdb# create user user2 passworduser21234;CREATE ROLE testdb#如上所示我们在mydb库中创建了两个用户user1和user2。此时查询库中的schema可以发现已经自动创建了同名的schema。如下所示testdb# \dn List of schemas Name | Owner ------------------------------- blockchain | gaussdb cstore | gaussdb db4ai | gaussdb dbe_application_info | gaussdb 省略部分输出信息 sys | gaussdb test | test user1 | user1 user2 | user2(41 rows)4.2 授权前建表测试尝试分别使用用户USER1和USER2在各自的SCHEMA中创建表。过程如下[gaussdblocalhost~]$ gsql -d testdb -Uuser1 -Wuser11234-r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser1via socket in/gaussdb/tmpat port8000. testdb testdb create table user1_tab1(id int);CREATE TABLE testdb \q [gaussdblocalhost~]$ gsql -d testdb -Uuser2 -Wuser21234-r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser2via socket in/gaussdb/tmpat port8000. testdb testdb create table user2_tab1(id int);CREATE TABLE testdb \q [gaussdblocalhost ~]$再尝试使用用户user1在user2中创建表过程如下[gaussdblocalhost~]$ gsql -d testdb -Uuser1 -Wuser11234-r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser1via socket in/gaussdb/tmpat port8000. testdb testdb create table user2.user1_tab2(id int);ERROR:Permission denied for schema user2.DETAIL:N/A. testdb如上所示提示权限不足。4.3 为用户USER1授权为用户USER1授予create any table的权限。过程如下[gaussdblocalhost~]$ gsql -d testdb -r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb# \conninfo You are connected to databasetestdbas usergaussdbvia socket in/gaussdb/tmpat port8000. testdb# testdb# grant create any table to user1;GRANT testdb# \q [gaussdblocalhost ~]$然后再测试使用用户user1在user2中创建表过程如下[gaussdblocalhost~]$ gsql -d testdb -Uuser1 -Wuser11234-r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser1via socket in/gaussdb/tmpat port8000. testdb testdb create table user2.user1_tab2(id int);CREATE TABLE testdb4.4 查询相关表的OWNER信息查询前述创建表的OWNER信息结果如下[gaussdblocalhost~]$ gsql -d testdb -Uuser1 -Wuser11234-r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser1via socket in/gaussdb/tmpat port8000. testdb testdb create table user2.user1_tab2(id int);CREATE TABLE testdb testdb \dt user2.user1_tab2;List of relations Schema | Name | Type | Owner | Size | Storage | Descrip tion --------------------------------------------------------------------------------------------------------------------- ----- user2 | user1_tab2 | table | | 0 bytes |{orientationrow,compressionno,storage_typeUSTORE,segmentoff}|(1 row)testdb \q如上所示此时owner列中的值为空。切换到user2再次查看该表的OWNER信息[gaussdblocalhost~]$ gsql -d testdb -Uuser2 -Wuser21234-r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser2via socket in/gaussdb/tmpat port8000. testdb testdb \dt user2.user1_tab2;List of relations Schema | Name | Type | Owner | Size | Storage | Descrip tion --------------------------------------------------------------------------------------------------------------------- ----- user2 | user1_tab2 | table | user2 | 0 bytes |{orientationrow,compressionno,storage_typeUSTORE,segmentoff}|(1 row)testdb如上所示我们可以看到显示该表的OWNER为user2即该表所在SCHEMA同名的OWNER。但当不存在与所在SCHEMA同名的用户时会是什么情况呢我们通过实际操作来验证首先我们创建一个新的SCHEMA名为USER2_B且并不存在名为USER2_B的用户。设置该SCHEMA的OWNER为USER2创建过程如下[gaussdblocalhost~]$ gsql -d testdb -r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb# \conninfo You are connected to databasetestdbas usergaussdbvia socket in/gaussdb/tmpat port8000. testdb# testdb# create schema user2_b authorization user2;CREATE SCHEMA testdb# \dn List of schemas Name | Owner ------------------------------- blockchain | gaussdb cstore | gaussdb db4ai | gaussdb dbe_application_info | gaussdb dbe_compression | gaussdb 省略部分输出 sys | gaussdb test | test user1 | user1 user2 | user2 user2_b | user2(42 rows)testdb#然后使用user1在schema user2_b 中创建一个新表过程如下[gaussdblocalhost~]$ gsql -d testdb -Uuser1 -Wuser11234-r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb create table user2_b.user1_tab3(id int);CREATE TABLE 查看该表的OWNER testdb \dt user2_b.user1_tab3;List of relations Schema | Name | Type | Owner | Size | Storage | Descri ption --------------------------------------------------------------------------------------------------------------------- ------ user2_b | user1_tab3 | table | user1 | 0 bytes |{orientationrow,compressionno,storage_typeUSTORE,segmentoff}|(1 row)testdb如上所示该表的OWNER为USER1。虽然所在的SCHEMA USER2_B的OWNER是USER2但因为无与USER2_B同名的用户所以该表的OWNER仍为其初始创建者–USER1。继续查看两个用户最初创建的user1_tab1和user2_tab1两张表的OWNER信息[gaussdblocalhost~]$ gsql -d testdb -Uuser1 -Wuser11234 -r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser1via socket in/gaussdb/tmpat port8000. testdb testdb \dt user1_tab1 List of relations Schema | Name | Type | Owner | Size | Storage | Descrip tion --------------------------------------------------------------------------------------------------------------------- ----- user1 | user1_tab1 | table | user1 | 0 bytes |{orientationrow,compressionno,storage_typeUSTORE,segmentoff}|(1 row)testdb testdb \q [gaussdblocalhost~]$ gsql -d testdb -Uuser2 -Wuser21234 -r gsql((GaussDB Kernel 505.2.0.SPC0100 build 8db8eac8)compiled at 2024-11-02 19:03:49 commit 9980 last mr 20502 release)Non-SSL connection(SSL connection is recommended when requiring high-security)Typehelpfor help. testdb \conninfo You are connected to databasetestdbas useruser2via socket in/gaussdb/tmpat port8000. testdb testdb \dt user2_tab1 List of relations Schema | Name | Type | Owner | Size | Storage | Descrip tion --------------------------------------------------------------------------------------------------------------------- ----- user2 | user2_tab1 | table | user2 | 0 bytes |{orientationrow,compressionno,storage_typeUSTORE,segmentoff}|(1 row)testdb如上所示可以看到各表的OWNER是与该表所在的SCHEMA同名的OWNER。即表在哪个SC。