服务注册成功后,启动数据库,如下所示:
systemctl start DmServicedm.service
停止数据库,如下所示:
systemctl stop DmServicedm.service
重启数据库,如下所示:
systemctl restart DmServicedm.service
查看数据库服务状态,如下所示:
systemctl status DmServicedm.service
切换目录到大梦数据库的bin目录下
登录数据库
[root@localhost bin]# ./disql SYSDBA/SYSDBA@localhost:5236
连接项目
mvn install:install-file -Dfile=F:\DMDb\drivers\jdbc\DmJdbcDriver18.jar -DgroupId=com.dm -DartifactId=DmJdbcDriver -Dversion=1.8.0 -Dpackaging=jar
./dminit PATH=/home/dm8/data PAGE_SIZE=32 EXTENT_SIZE=32 CASE_SENSITIVE=N CHARSET=1 LENGTH_IN_CHAR=Y DB_NAME=usky_fire BLANK_PAD_MODE=1 LOG_SIZE=2048 INSTANCE_NAME=usky_fire PORT_NUM=5236
./dm_service_installer.sh -t dmserver -p DMSERVERusky_fire -dm_ini /home/dm8/data/usky_fire/dm.ini
./dm_service_uninstaller.sh -n 实例/服务名(例如:DmServiceSP)
CREATE TABLESPACE alarm_electrical_fire
DATAFILE '/home/dm8/data/usky_fire/alarm_electrical_fire.dbf' SIZE 1M AUTOEXTEND ON NEXT 10M;
create tablespace alarm_spray_water datafile '/home/dm8/data/usky_fire/alarm_spray_water.dbf' size 128 autoextend on next 5 cache=normal;
SELECT TABLE_NAME FROM USER_TABLES;
TABLESPACE alarm_electrical_fire;
SELECT TABLESPACE_NAME, TABLESPACE_TYPE, TABLESPACE_SIZE
FROM SYS_ALL_TABLESPACES;
SELECT * FROM V$TABLESPACE;
SELECT TABLE_NAME, COLUMN_COUNT, ROW_COUNT
FROM SYS_TABLES
WHERE TABLESPACE_NAME = 'alarm_hydrant_water';
SELECT * FROM ALL_TABLES WHERE TABLESPACE_NAME = '表空间名称';
SELECT * FROM DBA_TABLES WHERE TABLESPACE_NAME = 'alarm_spray_water';
SELECT OWNER AS SCHEMA_NAME
FROM ALL_TABLES
WHERE TABLE_NAME = 'bsc_enterprise_screen';
DROP TABLESPACE tablespace_name INCLUDING CONTENTS;
CREATE TABLESPACE new_tablespace_name DATAFILE 'path_to_datafile' SIZE 100M;
在上述语句中,new_tablespace_name
是新表空间的名称,path_to_datafile
是数据文件的路径和名称,SIZE 100M
是指定表空间的大小。
ALTER TABLE table_name MOVE TABLESPACE new_tablespace_name;
在上述语句中,table_name
是要移动的表的名称,new_tablespace_name
是目标表空间的名称。
DROP TABLESPACE old_tablespace_name INCLUDING CONTENTS;
在上述语句中,old_tablespace_name
是要删除的旧表空间的名称。INCLUDING CONTENTS
参数可以选择是否删除表空间中的所有对象和数据。
SQL
脚本两种操作,当然需要登录到数据库中才能操作(导出dexp、dmp
文件不需要登录数据库)
1 # start + 脚本的绝对路径
2 SQL> start /home/dm8/data/usky_fire/alarm_hydrant_water(DM).sql
run /path/to/sql/file.sql;
@/path/to/sql/file.sql;
1 # ` + 脚本的绝对路径
2 SQL> `start /home/dm8/data/usky_fire/alarm_hydrant_water(DM).sql
dmp
文件使用dexp
进行导出,切换到达梦的bin目录下,可以看到有一个dexp
文件,使用它进行导出的操作
1 ./dexp 用户id/密码@ip:5236 file=导出的文件 directory=导出文件所在的目录 导出的模式
导出模式:FULL、OWNER、SCHEMAS、TABLES
;全部导出、根据用户导出、根据模式导出和表导出。
1 # 全部导出
2 [root@localhost bin]# ./dexp SYSDBA/SYSDBA@localhost:5236 file=imp_exp.dmp directory=/dm7/data FULL=y
3 # 根据模式导出
4 [root@localhost bin]# ./dexp SYSDBA/SYSDBA@localhost:5236 file=imp_exp.dmp directory=/dm7/data SCHEMAS=NINGDATABASE
dmp
文件使用dimp
进行导入,依旧需要切换到达梦的bin目录下,同样也会有一个dimp
文件,使用这个文件进行导入操作
1 ./dimp 用户id/密码@ip:5236 file=导入的文件 directory=导入文件所在的目录 导入的模式
和导出一样,导入也是同样的四个模式
1 #根据模式进行导入
2 [root@localhost bin]# ./dimp SYSDBA/SYSDBA@localhost:5236 file=imp_exp.dmp directory=/dm7/data SCHEMAS=NINGDATABASE
SQL
脚本和dmp
文件select * from v$version;
select * from v$license;
select name,create_time from v$database;
--大小敏感(1为大小写敏感,0为大小写不敏感)
SELECT SF_GET_CASE_SENSITIVE_FLAG();
或
SELECT CASE_SENSITIVE();
SELECT SF_GET_CASE_SENSITIVE_FLAG();
select SF_GET_PARA_VALUE(2,'MAX_SESSIONS');
select status$ from v$instance;
select EXPIRED_DATE from v$license;
select GROUP_ID , ID ,path,STATUS$ from v$datafile;
select FILE_NAME,FILE_ID,TABLESPACE_NAME,BYTES/1024/1024||'M' from dba_data_files;
select t1.NAME tablespace_name,
t2.FREE_SIZE*SF_GET_PAGE_SIZE()/1024/1024 ||'M' free_space,
t2.TOTAL_SIZE*SF_GET_PAGE_SIZE()/1024/1024 ||'M' total_space,
t2.FREE_SIZE*100/t2.total_size "% FREE"
from V$TABLESPACE t1, V$DATAFILE t2
where t1.ID=t2.GROUP_ID;
select * from dba_objects where object_type='SCH';
select username from dba_users;
set schema "testSchema";
CREATE SCHEMA "testSchema";
select TABLE_NAME from all_tables WHERE OWNER='testSchema';
drop schema "testSchema";
COMMENT ON COLUMN testSchema.peoples.role_id is '角色Id';
select * from SYSCOLUMNCOMMENTS
where SCHNAME='testSchema' and TVNAME='peoples' and COLNAME='role_id';
comment on table testSchema.peoples is '这是一个表注释';
select * from SYSTABLECOMMENTS where SCHNAME='testSchema' and TVNAME='peoples';
SELECT COMMENTS
FROM USER_TAB_COMMENTS
WHERE TABLE_NAME = 'alarm_electrical_fire';
CREATE TABLESPACE MANAGEMENT DATAFILE 'MANAGEMENT.DBF' SIZE 128;
select * from dba_data_files;
select * from dba_tablespaces;
select * from v$tablespace;
CREATE USER usky_cloud IDENTIFIED BY "usky666" DEFAULT TABLESPACE MANAGEMENT;
GRANT DBA TO testSchema;
GRANT DBA TO usky_cloud;
select clnt_ip,user_name,state,count(*) from v$sessions group by clnt_ip,user_name,state;
查询 dba_segments 需要Dba权限,用户没有Dba权限时查询 all_tables 或 user_tables
某模式下所有表名 需要DBA权限 AND SEGMENTNAME LIKE 'CD%'
select owner,SEGMENT_NAME as tbName from dba_segments where segment_type='TABLE' and OWNER ='模式名'
查看模式下所有表 不需要DBA权限 and TABLENAME LIKE 'CD%'
select TABLE_NAME as tbName from all_tables where OWNER ='模式名'
用户下所有表 where tablename like 'CD%'
select table_name as tbName from user_tables group by TABLE_NAME
cd /home/dmdba/dmdbms/bin
./dmserver /home/dmdba/dmdbms/DAMENG/dm.ini
./disql SYSDBA/SYSDBA@localhost:5236
cd /home/dmdba/dmdbms/bin
./disql SYSDBA/SYSDBA -E "select * from t1"
select *,id_code from v$version;
select * from v$database;
// 查看表结构
SQL > describe table
// 查看表的模式名
select owner from dba_tables where table_name='T1';
// 查看数据库中的表
select * from dba_tables;
// 查看建表语句
sp_tabledef('SYSDBA','T1'); -- 模式名,表名,注意都要大写。
SELECT DBMS_METADATA.GET_DDL('TABLE',表名,模式名); // 参考 DBMS_METADATA 系统包
SELECT DBMS_METADATA.GET_DDL('TABLE','T1','SYSDBA'); // 例句
SQL > SELECT * FROM V$LICENSE;
//修改数据库为MOUNT状态
ALTER DATABASE MOUNT;
//配置本地归档
ALTER DATABASE ADD ARCHIVELOG 'DEST = /dmdata/dameng/arch_dsc0, TYPE = local, FILE_SIZE = 1024, SPACE_LIMIT = 2048, ARCH_FLUSH_BUF_SIZE=16,HANG_FLAG=1';
//配置远程归档
ALTER DATABASE ADD ARCHIVELOG 'DEST = DSC1, TYPE = REMOTE, FILE_SIZE = 1024, SPACE_LIMIT = 2048, ARCH_FLUSH_BUF_SIZE=16, INCOMING_PATH = /dmdata/dameng/arch_dsc1';
//开启归档模式
ALTER DATABASE ARCHIVELOG;
//修改数据库为OPEN状态
ALTER DATABASE OPEN;
// 必须开启归档并已生成归档日志
dmdba@else-virtual-machine:~/dmdbms/bin$ ./dmrman
dmrman V8
RMAN> BACKUP DATABASE '/home/dmdba/dmdbms/DAMENG/dm.ini' FULL BACKUPSET '/else/bakup_dm';
SQL> BACKUP DATABASE TO WEEKLY_FULL_BAK BACKUPSET '/backup/dmdb/online';
SQL> BACKUP DATABASE FULL BACKUPSET '/backup/dmdb/online';
SQL> BACKUP TABLE t1 BACKUPSET '/backup/dmdb/t1_bak_01';
// 前提: 表必须存在
SQL> RESTORE TABLE t1 FROM BACKUPSET '/backup/dmdb/t1_bak_01';
// 数据库状态查看
SQL> select status$ from v$instance;
// 数据库模式查看
SQL> select MODE$ from v$instance;
SQL> select * from V$ARCH_STATUS
SQL> select * from V$RLOG_RAFT_INFO