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

openGauss每日一练第5天|多数据库访问

原创 吴杰克 2022-11-28
151

openGauss每日一练第5天

1.创建数据库musicdb10,创建用户user10,赋予sysadmin权限

su - omm gsql -r --进入数据库omm,创建表空间music_tbs10、测试数据库musicdb10 drop DATABASE IF EXISTS musicdb10; drop tablespace IF EXISTS music_tbs10; CREATE TABLESPACE music_tbs10 RELATIVE LOCATION 'tablespace/Mygstest_ts10'; CREATE DATABASE musicdb10 WITH TABLESPACE = music_tbs10; --创建用户user10: CREATE USER user10 IDENTIFIED BY 'Mygstest@1234'; --授予user10数据库系统的SYSADMIN权限: ALTER USER user10 SYSADMIN;
root@modb:~# su - omm omm@modb:~$ gsql -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm=# drop DATABASE IF EXISTS musicdb10; NOTICE: database "musicdb10" does not exist, skipping DROP DATABASE omm=# drop tablespace IF EXISTS music_tbs10; omm=# NOTICE: Tablespace "music_tbs10" does not exist, skipping. DROP TABLESPACE CREATE TABLESPACE music_tbs10 RELATIVE LOCATION 'tablespace/Mygstest_ts10'; CREATE TABLESPACE omm=# CREATE DATABASE musicdb10 WITH TABLESPACE = music_tbs10; CREATE DATABASE omm=# CREATE USER user10 IDENTIFIED BY 'Mygstest@1234'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# ALTER USER user10 SYSADMIN; ALTER ROLE

2.用户user10访问数据库postgres,创建一个表并插入数据

--以用户user10的身份在数据库postgres中创建表mytest1,并插入数据: \c postgres user10 create table mytest1(product_id INTEGER,product_name Char(20),category Char(30)); insert into mytest1 values(1502,'olympus camera','electrncs'),(1601,'lamaze','toys'),(1700,'wait interface','Books'),(1666,'harry potter','toys'); select * from mytest1;
omm=# \c postgres user10 Password for user user10: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "postgres" as user "user10". openGauss=> create table mytest1(product_id INTEGER,product_name Char(20),category Char(30)); CREATE TABLE openGauss=> insert into mytest1 values(1502,'olympus camera','electrncs'),(1601,'lamaze','toys'),(1700,'wait interface','Books'),(1666,'harry potter','toys'); INSERT 0 4 openGauss=> select * from mytest1; product_id | product_name | category ------------+----------------------+-------------------------------- 1502 | olympus camera | electrncs 1601 | lamaze | toys 1700 | wait interface | Books 1666 | harry potter | toys (4 rows) openGauss=>

3.用户user10访问数据库omm,创建一个表并插入数据

--以用户user10的身份在数据库omm中创建表mytest2,并插入数据: \c omm user10 create table mytest2(product_id INTEGER,product_name Char(20),category Char(30)); insert into mytest2 values(1502,'olympus camera','electrncs'),(1601,'lamaze','toys'),(1700,'wait interface','Books'),(1666,'harry potter','toys'); select * from mytest2;
omm=# \c omm user10 Password for user user10: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "omm" as user "user10". omm=> create table mytest2(product_id INTEGER,product_name Char(20),category Char(30)); omm=> CREATE TABLE omm=>insert into mytest1 values(1502,'olympus camera','electrncs'),(1601,'lamaze','toys'),(1700,'wait interface','Books'),(1666,'harry potter','toys'); INSERT 0 4 omm=> select * from mytest2; product_id | product_name | category ------------+----------------------+-------------------------------- 1502 | olympus camera | electrncs 1601 | lamaze | toys 1700 | wait interface | Books 1666 | harry potter | toys (4 rows)

4.用户user10访问数据库musicdb10,创建一个表并插入数据

--以用户user10的身份在数据库musicdb10中创建表mytest3,并插入数据: \c musicdb10 user10 create table mytest3(product_id INTEGER,product_name Char(20),category Char(30)); insert into mytest3 values(1502,'olympus camera','electrncs'),(1601,'lamaze','toys'),(1700,'wait interface','Books'),(1666,'harry potter','toys'); select * from mytest3;
omm=> \c musicdb10 user10 Password for user user10: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb10" as user "user10". musicdb10=> create table mytest3(product_id INTEGER,product_name Char(20),category Char(30)); CREATE TABLE musicdb10=> insert into mytest3 values(1502,'olympus camera','electrncs'),(1601,'lamaze','toys'),(1700,'wait interface','Books'),(1666,'harry potter','toys'); INSERT 0 4 musicdb10=> select * from mytest3; product_id | product_name | category ------------+----------------------+-------------------------------- 1502 | olympus camera | electrncs 1601 | lamaze | toys 1700 | wait interface | Books 1666 | harry potter | toys (4 rows) musicdb10=>
最后修改时间:2022-12-03 16:56:06
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论