- 通过disql连接数据库。
- 进入目录DM8/bin目录下[dmdba@localhost /]$ cd DM8/bin
- 启动disql工具[dmdba@localhost bin]$ ./disql
输入用户名SYSDBA,密码SYSDBA,默认连接端口为5236
- 查看数据库状态SQL> select INSTANCE_NAME,STATUS$ from v$instance;
- 从open状态改为配置模式SQL> alter database mount;
- 从配置模式改为open状态SQL> alter database open;
- 从open状态改为挂起状态SQL> alter database suspend;
- 从挂起状态改为open状态SQL> alter database open;
- 数据库直接关闭SQL> shutdown normal;
- 服务重启
- 服务状态查看[root@localhost system]# systemctl status DmServiceDMSERVER
- 查看日志文件大小SQL> select path,rlog_size/1024/1024 from v$rlogfile;
- 修改日志文件大小:注意所有的日志文件必须同时修改,并且大小一样。达梦要求 至少有两个日志文件。
SQL> alter database resize logfile '/DM8/data/DAMENG/DAMENG01.log' to 500;
SQL> alter database resize logfile '/DM8/data/DAMENG/DAMENG02.log' to 500;
- 控制文件备份位置查询SQL> select para_name,para_value from v$dm_ini where para_name='CTL_PATH';
- 共享内存总容量查询SQL> select para_name,para_value from v$dm_ini where para_name='MEMORY_TARGET';
- 共享内存总容量大小修改SQL> sp_set_para_value(1,'MEMORY_TARGET',1024);
- 公共池查询SQL> select para_name,para_value,para_type from v$dm_ini where para_name='MEMORY_POOL';
- 数据缓冲池查询select para_name,para_value,para_type from v$dm_ini where para_name='BUFFER';
- 字典缓冲区查询SQL> select para_name,para_value,para_type from v$dm_ini where para_name='DICT_BUF_SIZE';
- SQL缓冲区查询SQL> select para_name,para_value,para_type from v$dm_ini where para_name='CACHE_POOL_SIZE';
- 表空间信息查询SQL> select tablespace_name from dba_tablespaces;
- 页大小查询SQL> select page; 注意初始大小必须是页的4096倍。
- 表空间初始大小计算SQL> select 4096*8/1024;
- 表空间创建SQL> create tablespace tbs datafile '/DM8/data/DAMENG/tbs.dbf' size 32 autoextend on maxsize 1024;
- 一个表空间下有两个数据文件SQL> create tablespace tbs1 datafile '/DM8/data/DAMENG/tbs1_1.dbf' size 32 autoextend on next 1 maxsize 1024,'/DM8/data/DAMENG/tbs1_2.dbf' size 32 autoextend on next 1 maxsize 1024;
- 表空间状态查询SQL> select tablespace_name,status from dba_tablespaces;
- 临时表空间信息查询SQL> select para_name,para_value from v$dm_ini where para_name like 'TEMP%';
- 修改临时表空间大小SQL> sp_set_para_value(2,'TEMP_SIZE',100); 修改之后需要重启服务才会生效。
- 删除表空间SQL> drop tablespace tbs1;
- 用户信息查询SQL> select username from dba_users;
- 新建用户SQL> create user user1 identified by "dameng123" default tablespace tbs;
- 查询用户默认权限SQL> select grantee,granted_role from dba_role_privs where grantee='USER1';
- 查询角色权限SQL> select grantee,privilege from dba_sys_privs where grantee='PUBLIC';
- 给用户授权SQL> grant create table to user1;
- 撤销授权SQL> revoke create table from user1;
- 创建角色SQL> create role r1;
- 给角色授权SQL> grant create table to r1;
- 把角色分配给用户SQL> grant r1 to user1;
- 修改用户密码SQL> alter user user1 identified by "dameng1234";
- 锁定用户SQL> alter user user1 account lock;
- 解锁用户SQL> alter user user2 account unlock;
- 级联删除用户SQL>drop user user1 cascade;
- 创建表SQL> create table t1 (id int not null);
- 插入表数据SQL> insert into t1 values (null);
- 查看表创建语句SQL> sp_tabledef('USER1','T1');
- 删除表SQL>drop table test;
- 视图创建SQL> create view v1 as select * from dmhr.city;
- 视图修改重建SQL> create or replace view v1 as select city_name from dmhr.city;
- 视图删除SQL> drop view v1;
- 新建表SQL> create table emp as select * from dmhr.employee;
- 在emp表上新建索引SQL> create index ind_emp on emp(employee_id);
- 在线重建索引SQL> alter index ind_emp rebuild online;
- 删除索引SQL> drop index ind_emp;
- DML数据管理语句查询.insert、delete、update、select
--查询名字只有两个字的员工信息
select employee_name from dmhr.employee where
employee_name like '__';
--获得工资在19000到30000之间的员工信息。
select employee_name,salary from dmhr.employee
where salary between 19000 and 30000;
--按照薪水排降序
select employee_name,salary from dmhr.employee
order by 2 desc;
获取工资总和大于200000的部门信息。
select department_id,sum(salary) from
dmhr.employee group by department_id having
sum(salary)>200000;
--交叉链接
select * from dmhr.employee cross join dmhr.department;
--自然链接
select employee_name,department_name from employee natural join department;
--using字句,相当于on
select employee_name,department_name from employee join department using (department_id);
--on字句
select employee_name,department_name from
employee e join department d
on e.department_id=d.department_id;
--hash join链接
select employee_name,department_name from
employee e inner hash join department d on e.department_id=d.department_id;
--自连接
select e.employee_name,m.employee_name from
employee e join employee m on e.manager_id=m.employee_id;
--左外连接
select e.employee_name,d.department_name from
employee e left join department d on e.department_id=d.department_id;
--右外连接
select e.employee_name,d.department_name from
employee e right join department d on e.department_id=d.department_id;
--全外连接
select e.employee_name,d.department_name from
employee e full join department d on e.department_id=d.department_id;