美文网首页
Gauss DB 数据库使用(一)

Gauss DB 数据库使用(一)

作者: Kindey_S | 来源:发表于2020-03-12 09:14 被阅读0次

前提

GaussDB 200集群正常运行。

hello word

omm

以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。

[root@zhdata1 software]# su - omm
Last login: Wed Mar 11 16:38:14 CST 2020
[omm@zhdata1 ~]$ source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile

gsql连接数据库

postgres为集群安装完成后默认生成的数据库。初始可以连接到此数据库进行新数据库的创建。25308为CN的端口号,需根据集群的实际情况做替换。

[omm@zhdata1 ~]$ gsql -d postgres -p 25308
gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 20:23:44 commit 6093 last mr 10175 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

postgres=# 

创建数据库用户

默认只有集群安装时创建的管理员用户可以访问初始数据库,您还可以创建其他数据库用户帐号。

postgres=# CREATE USER u_test WITH PASSWORD "test123.";
CREATE ROLE
postgres=# 

创建数据库。

postgres=# CREATE DATABASE db_test;
CREATE DATABASE
postgres=# 

创建完db_test数据库后,就可以按如下方法退出postgres数据库,使用新用户连接到此数据库执行接下来的创建表等操作。

postgres=# \q
[omm@zhdata1 ~]$ gsql -d postgres -p 25308 -U u_test -W test123.
gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 20:23:44 commit 6093 last mr 10175 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

postgres=> 

创建表

未使用“DISTRIBUTE BY”指定分布列时,系统默认会指定第一列为分布列,且给出提示。系统返回信息以“CREATE TABLE”结束,表示创建表成功。

postgres=> CREATE TABLE t_tets (c1 int);
NOTICE:  The 'DISTRIBUTE BY' clause is not specified. Using 'c1' as the distribution column by default.
HINT:  Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
CREATE TABLE
postgres=> 

向表中插入数据

postgres=> INSERT INTO t_tets values (100);
INSERT 0 1
postgres=> 

查看表中数据

postgres=> select * from t_tets;
 c1  
-----
 100
(1 row)

postgres=> 

相关文章

网友评论

      本文标题:Gauss DB 数据库使用(一)

      本文链接:https://www.haomeiwen.com/subject/qcoejhtx.html