前言:
最近参加了由opengauss、墨天轮、鲲鹏社区一起推出的活动《每日一练 opengauss 3.0.0 数据库在线实训课程》,共21天,墨天轮提供实操环境,特此记录学习笔记。
活动详情:https://www.modb.pro/db/551619
主题:
学习openGauss体系结构,使用一个用户访问多个数据库。
学习笔记:
数据库用户user10可以访问不同的数据库(postgres、omm、musicdb10)。
实验中user10用户在数据库postgres中创建了表t11、在数据库omm创建了表t21、在数据库musicdb10中创建了表t31,验证了这个结论。
1.进入数据库omm,创建表空间、测试数据库
su - omm
gsql -r
CREATE TABLESPACE music_tbs RELATIVE LOCATION 'tablespace/test_ts1';
CREATE DATABASE musicdb10 WITH TABLESPACE = music_tbs;
|
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=#
omm=# CREATE TABLESPACE music_tbs RELATIVE LOCATION ‘tablespace/test_ts1’;
CREATE TABLESPACE
omm=# CREATE DATABASE musicdb10 WITH TABLESPACE = music_tbs;
CREATE DATABASE
omm=#
|
2.执行下面的SQL语句,创建用户user10并授予SYSADMIN权限:
CREATE USER user10 IDENTIFIED BY 'kunpeng@1234';
ALTER USER user10 SYSADMIN;
|
omm=# CREATE USER user10 IDENTIFIED BY ‘kunpeng@1234’;
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# ALTER USER user10 SYSADMIN;
ALTER ROLE
omm=#
|
3.分别使用user10登录不同的数据库,建表并插入数据
使用数据库用户user10登录到数据库musicdb10,创建一个表t11,并插入一条数据:
–用户user10登录到数据库postgres,创建表t11,并插入、查看数据
\c postgres user10
create table t11(col1 char(20));
insert into t11 values('Hello openGauss! 11');
select * from t11;
|
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 t11(col1 char(20));
CREATE TABLE
openGauss=> insert into t11 values(‘Hello openGauss! 11’);
INSERT 0 1
openGauss=> select * from t11;
col1
-~ - - - - - ----------------
Hello openGauss! 11
(1 row)
openGauss=>
|
使用数据库用户user10登录到数据库omm ,创建一个表t21,并插入一条数据:
–用户user10登录到数据库omm ,创建表t21,并插入、查看数据
\c omm user10
create table t21(col1 char(20));
insert into t21 values('Hello openGauss! 22');
select * from t21;
|
openGauss=> \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 t21(col1 char(20));
CREATE TABLE
omm=> insert into t21 values(‘Hello openGauss! 22’);
INSERT 0 1
omm=> select * from t21;
col1
-.---------------------
Hello openGauss! 22
(1 row)
omm=>
|
使用数据库用户user10登录到数据库musicdb10 ,创建一个表t31,并插入一条数据:
–用户user1登录到数据库musicdb10 ,创建表t31,并插入、查看数据
\c musicdb10 user10
create table t31(col1 char(20));
insert into t31 values('Hello openGauss! 33');
select * from t31;
|
omm=> \c musicdb10 user10
Password for user user10:
musicdb10=> Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database “musicdb10” as user “user10”.
musicdb10=> create table t31(col1 char(20));
CREATE TABLE
musicdb10=> insert into t31 values(‘Hello openGauss! 33’);
INSERT 0 1
musicdb10=> select * from t31;
(1 row)
musicdb10=> col1
-.---------------------
Hello openGauss! 33
musicdb10=>
|
总结
通过第五天的学习中,我们学到了一个用户可以访问多个数据库。