暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第 4 天 | openGauss中一个数据库可以被多个用户访问

原创 SongF 2022-11-27
308

1.创建用户user1、user2、user3,授予user1、user2、user3数据库系统的SYSADMIN权限

omm=# create user user1 with sysadmin identified by 'abcd@123';
NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# create user user2 with sysadmin identified by 'abcd@123';
NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# create user user3 with sysadmin identified by 'abcd@123';
NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE

2.分别使用user1、user2、user3访问数据库musicdb2,创建各自的表,并插入数据。

-- 创建数据库musicdb2omm=# create database musicdb2;
CREATE DATABASE-- 以用户user1的身份在数据库musicdb2中创建表products1,并插入数据
omm=# \c musicdb2 user1 Password for user user1: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb2" as user "user1".
musicdb2=> create table products1 ( musicdb2(> product_id integer,musicdb2(> product_name char(20), musicdb2(> category char(30) musicdb2(> ); CREATE TABLE
musicdb2=> insert into products1 values musicdb2-> (1502,'olympus camera','toys'), musicdb2-> (1601,'lamaze','toys'), musicdb2-> (1700,'wait interface','Books'), musicdb2-> (1666,'harry potter','toys'); INSERT 0 4
-- 以用户user2的身份在数据库musicdb2中创建表products2,并插入数据
musicdb2=> \c musicdb2 user2 Password for user user2: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb2" as user "user2".
musicdb2=> create table products2 ( musicdb2(> product_id integer, musicdb2(> product_name char(20), musicdb2(> category char(30) musicdb2(> ); CREATE TABLE
musicdb2=> insert into products2 values musicdb2-> (1502,'olympus camera','toys'), musicdb2-> (1601,'lamaze','toys'), musicdb2-> (1700,'wait interface','Books'), musicdb2-> (1666,'harry potter','toys'); INSERT 0 4
-- 以用户user3的身份在数据库musicdb2中创建表products3,并插入数据
musicdb2=> \c musicdb2 user3 Password for user user3: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb2" as user "user3".
musicdb2=> create table products3 ( musicdb2(> product_id integer, musicdb2(> product_name char(20), musicdb2(> category char(30)
musicdb2(> ); CREATE TABLE
musicdb2=> insert into products3 values musicdb2-> (1502,'olympus camera','toys'), musicdb2-> (1601,'lamaze','toys'), musicdb2-> (1700,'wait interface','Books'), musicdb2-> (1666,'harry potter','toys'); INSERT 0 4

3.使用user1、user2、user3用户中的任何一个,查看当前数据库musicdb2有哪些表

musicdb2=> \d
                           List of relations
 Schema |   Name    | Type  | Owner |             Storage              
--------+-----------+-------+-------+----------------------------------
 public | products1 | table | user1 | {orientation=row,compression=no}
 public | products2 | table | user2 | {orientation=row,compression=no}
 public | products3 | table | user3 | {orientation=row,compression=no}
(3 rows)musicdb2=> select * from products1;
 product_id |     product_name     |            category            
------------+----------------------+--------------------------------
       1502 | olympus camera       | toys                          
       1601 | lamaze               | toys                          
       1700 | wait interface       | Books                         
       1666 | harry potter         | toys                          
(4 rows)
musicdb2=> select * from products2; product_id | product_name | category ------------+----------------------+-------------------------------- 1502 | olympus camera | toys 1601 | lamaze | toys 1700 | wait interface | Books 1666 | harry potter | toys (4 rows)
musicdb2=> select * from products3; product_id | product_name | category ------------+----------------------+-------------------------------- 1502 | olympus camera | toys 1601 | lamaze | toys 1700 | wait interface | Books 1666 | harry potter | toys (4 rows)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论