达梦数据库DM8 DCA认证学习笔记
遠程訪問數(shù)據(jù)庫需要關(guān)閉防火墻
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
一、 規(guī)劃路徑建立安裝位置文件夾 [root@localhost /]# mkdir -p /dm8
2.3 安裝用戶(建議不要使用 root)
[root@localhost /]# groupadd dinstall
[root@localhost /]# useradd -g dinstall dmdba
[root@localhost /]# passwd dmdba
[root@localhost /]# chown dmdba:dinstall /dm8 -R給權(quán)限
[root@localhost /]# ls -ld /dm8 查看讀寫權(quán)限
配置 dmdba 用戶環(huán)境變量(可選項)
[dmdba@localhost ~]$ source .bash_profile 環(huán)境變量生效:
[root@localhost /]# vi /etc/security/limits.conf設(shè)置最大文件打開數(shù)
dmdba soft nofile 4906
dmdba hard nofile 65536
臨時生效:ulimit -n 65536
圖形化安裝
[root@localhost home]# mount -o loop /home/dm8_setup_rh7.iso /mnt mount: /dev/loop0 寫保護,將以只讀方式掛載
[root@localhost mnt]# export DISPLAY=192.168.128.1:0.0 XSHELL下調(diào)出圖形化安裝
[root@localhost mnt]# xhost +
[root@localhost mnt]# export DISPLAY=192.168.164.100:0.0
[root@localhost mnt]# xhost +
access control disabled, clients can connect from any host
xhost: must be on local machine to enable or disable access control.
[dmdba@localhost ~]$ export DISPLAY=192.168.128.1:0.0
[dmdba@localhost ~]$ xhost +
access control disabled, clients can connect from any host
[dmdba@localhost mnt]$ ./DMInstall.bin
CLI:命令行的交互式安裝
[dmdba@localhost mnt]$ ./DMInstall.bin –i
卸載數(shù)據(jù)庫軟件(在卸載數(shù)據(jù)庫之前,需要將數(shù)據(jù)庫備份,然后關(guān)閉實例、刪除
數(shù)據(jù)庫及卸載數(shù)據(jù)庫軟件)
[dmdba@localhost dm8]$ ./uninstall.sh -i
創(chuàng)建數(shù)據(jù)庫實例:一個數(shù)據(jù)庫軟件是可以安裝多個實例,通過端口號來區(qū)分
[dmdba@localhost tool]$ ./dbca.sh
[root@localhost tool]# ./dmservice.sh 看服務(wù)
[dmdba@localhost ~]$ ps -ef|grep dmserver 判斷是否啟動
[dmdba@localhost ~]$ netstat -ntl|grep 5236 看端口是否被占用
[dmdba@localhost bin]$ ./DmServiceDMSERVER status
看數(shù)據(jù)庫實例服務(wù)
[root@localhost tool]# systemctl status DmServiceDMSERVER.service看數(shù)據(jù)庫實例服務(wù)
4、DM8 數(shù)據(jù)庫實例管理
4.1 數(shù)據(jù)庫的狀態(tài)
Shutdown:關(guān)閉狀態(tài)
Mount:配置狀態(tài)
Open:數(shù)據(jù)庫打開狀態(tài),數(shù)據(jù)庫對外提供服務(wù)
Suspend:掛起狀態(tài)
4.2 數(shù)據(jù)庫狀態(tài)的切換
在bin下面用 cd 查詢腳本
select instane_name from V i n s t a n e ; s e l e c t s t a t u s instane; select status instane;selectstatus from V$instance; 查詢狀態(tài)
alter database mount; 切換為編輯模式
alter database open;
Shutdown -mount
Shutdown -open
Open-shutdown
Mount-open
Open-mount(oracle 不支持)
Open-suspend
Suspend-openDm 數(shù)據(jù)庫不支持 mount-suspend 狀態(tài),suspend-mount 狀態(tài)
Exit退出
4.4 數(shù)據(jù)庫和關(guān)閉
.
[dmdba@localhost bin]$ ./DmServiceDMSERVER stop
[dmdba@localhost bin]$ ./DmServiceDMSERVER start
exit在前端啟停數(shù)據(jù)庫
[dmdba@localhost bin]$ ./dmserver /dm8/data/DAMENG/dm.ini
5、數(shù)據(jù)庫工具
5.1 disql
[dmdba@localhost bin]$ ./disql SYSDBA/dameng123:5239
[dmdba@localhost bin]$ cd /dm8/tool/
[dmdba@localhost tool]$ ./disql
disql V8
SQL> conn SYSDBA/SYSDBA:5239在tool下面用需要使用連接數(shù)據(jù)庫
5.2 管理工具 manager
./manager
5.3 性能監(jiān)控工具 monitor
./monitor
5.4 遷移工具 dts
./dts
5.5console 工具
查看和調(diào)整參數(shù)
6、DMSQL
結(jié)構(gòu)化查詢語言,提供了應(yīng)用程序到數(shù)據(jù)庫的一個接口。
6.1DMSQL 分類
DML(數(shù)據(jù)操作語言):insert update delete select
DDL(數(shù)據(jù)定義語言):create table,drop table,alter table ,truncate
DCL(數(shù)據(jù)控制語言):權(quán)限的授予或撤回,grant,revoke
TCL(事務(wù)控制語言):commit, rollback ,save moint
6.2SQL 語句規(guī)范
SQL 不區(qū)分大小寫,除了’’ “”除外
關(guān)鍵字是不能被拆分,不能縮寫
可以換行,可以縮進,提高閱讀性
6.3 簡單查詢
語法:
Select () from ();
單列查詢
select employee_id from dmhr.employee;
查詢多列
select * from dmhr.employee;
表達式:select
employee_id,employee_name,salary,salary+500 from dmhr.employee;
起別名:(方便識別,計算)
select
employee_id,employee_name,salary,salary+500 tol from dmhr.employee;
去重復(fù):(隱含排序 升序)
select distinct department_id from dmhr.department;
連接||
“xxx 的工資是:xxx”
select employee_name || ‘的工資是:’ || salary from dmhr.employee;
6.4 過濾查詢
語法:
Select () from () where ()
比較運算符、邏輯運算符、
in、between*** and、is null/is not null、like
比較運算符:> >= < <= <> != =
select employee_name,salary from dmhr.employee where salary>=30000;
邏輯運算符:and or not
And 同時滿足:
select employee_name,department_id,salary from dmhr.employee
where department_id=101 and salary>15000;or 滿足一個條件即可:
select employee_name,department_id,salary from dmhr.employee
where department_id=101 or salary>15000;
Is null/is not null null 為空但是不等于 0
select employee_name,job_id from dmhr.employee where job_id is null;
select employee_name,job_id from dmhr.employee where job_id is not
null;
IN
select employee_name,department_id from dmhr.employee where department_id in (101,104);
Between*** and
select employee_name,department_id,salary from dmhr.employee where salary between 20000 and 30000;
模糊查詢:like % _
%匹配 0 個或多個字符
匹配 1 個字符
select employee_name,salary from dmhr.employee where employee_name like ‘李%’;
select employee_name,salary from dmhr.employee where employee_name like '李’;6.5 排序
升序 asc
select employee_name,salary from dmhr.employee order by salary asc;
降序 desc
select employee_name,salary from dmhr.employee order by 2 desc;
分組函數(shù)
Count max min avg sum
語法:
Select () from () group by () having ();
除了聚合函數(shù)不用跟在 group by 后面,其他 select 列必須在 group by 后面,having 是對 group by 進一步過濾,having 不能單獨使用。
求部門工資和小于 8 萬的部門
select department_id,sum(salary) from dmhr.employee group by department_id having sum(salary) <80000;
6.7 多表連接
內(nèi)連接
結(jié)果集只顯示滿足條件的記錄
交叉連接(迪卡集)
兩個表記錄數(shù)的乘積
select count() from dmhr.employee cross join
dmhr.department;–39376
select count() from dmhr.employee;
select count(*) from dmhr.department;
自然連接
根據(jù)列名自己過濾,兩個表連接的列名和數(shù)據(jù)類型要一致
select employee_name,department_name from dmhr.employee natural
join dmhr.department;
USING
在滿足多個連接列時,可以指定某一個列做連接,一般是和NATURAL
JOIN 使用,連接的列前面不能加表名或者是前綴。
select employee_name,department_name from dmhr.employee join dmhr.department using (department_id);
ON 子句
select c.city_name,l.street_address from dmhr.city c join dmhr.location
l on c.city_id=l.city_id;
HASH JOIN
優(yōu)化器CBO 根據(jù)小表連接列做運算生成hash 值,根據(jù)hash 值去連接
大表,掃描大表
select e.employee_name,d.department_name from dmhr.employee einner hash join dmhr.department d
on e.department_id=d.department_id;
外連接
結(jié)果集除了顯示滿足條件的記錄,不滿足的用null 代替
左外連接
把left join 左邊的全部顯示出來,右邊只顯示滿足條件的,不滿足條
件的用null 補齊
select a.employee_name,b.department_name from dmhr.employee a
left join dmhr.department b
on a.department_id=b.department_id;
右外連接
把right join 右邊的全部顯示出來,左邊只顯示滿足條件的,不滿足
條件的用null 補齊
select a.employee_name,b.department_name from dmhr.employee a
right join dmhr.department b
on a.department_id=b.department_id;
全外連接
左外連接+右外連接
select a.employee_name,b.department_name from dmhr.employee a
full join dmhr.department b
on a.department_id=b.department_id;
6.8 子查詢
當(dāng)一個查詢是另一個查詢條件時,就叫子查詢。子查詢先運行,子查
詢的結(jié)果是外部查詢(主查詢)的條件
單行子查詢
= > >= < <= <>
找出和金緯在一個部門的員工
select employee_name,department_id from dmhr.employee where department_id=
(select department_id from dmhr.employee where employee_name=‘金緯’)
多行子查詢
In any all
查詢比104 部門工資都高的人
select department_id,employee_name,salary from dmhr.employee where salary > all
(select salary from dmhr.employee where department_id=104);
Exists
一旦有記錄滿足條件,就立馬返回值
SELECT E.EMPLOYEE_ID , E.EMPLOYEE_NAME FROM DMHR.EMPLOYEE
E
WHERE EXISTS
( SELECT * FROM DMHR.JOB_HISTORY J
WHERE E.EMPLOYEE_ID = J.EMPLOYEE_ID );
7、DM8 體系結(jié)構(gòu)
DMSERVER:C/S 架構(gòu),客戶端+服務(wù)器構(gòu)成
DMSERVER=數(shù)據(jù)庫文件+實例
實例=共享內(nèi)存+后臺進程/線程
非DSC 架構(gòu)是一個實例對應(yīng)一個數(shù)據(jù)庫,DSC 架構(gòu)是一個數(shù)據(jù)庫可以對應(yīng)多個實例
7.1DM8 存儲結(jié)構(gòu)
物理結(jié)構(gòu)
配置文件
以.ini 結(jié)尾的文件
查詢視圖:
select para_name,para_value from v$dm_ini where para_name like
‘COMPAT%’;
SYS 系統(tǒng)級:影響全局
Session 會話級:針對當(dāng)前會話有效
Infile:靜態(tài)參數(shù),實例重啟才能生效
sp_set_para_value(2,‘COMPATIBLE_MODE’,2);
1 等于both,會改變內(nèi)存和參數(shù)文件中的值。
2 等于infile,會改變參數(shù)文件中的值,重啟才能生效。
數(shù)據(jù)文件
以.DBF 結(jié)尾的文件
控制文件
以.ctl 結(jié)尾的文件
select para_name,para_value from v d m i n i w h e r e p a r a n a m e l i k e ′ 查 看 控 制 文 件 內(nèi) 容 : [ d m d b a @ l o c a l h o s t b i n ] dm_ini where para_name like '%PATH%'; 查看控制文件內(nèi)容: [dmdba@localhost bin] dmi?niwhereparan?amelike′查看控制文件內(nèi)容:[dmdba@localhostbin] ./dmctlcvt TYPE=1
SRC=/dm8/data/DAMENG/dm.ctl DEST=/tmp/dmctl.txt
注意:不要隨便修改控制文件
重做日志文件
查詢重做日志文件:
重做日志文件記錄的是數(shù)據(jù)庫發(fā)生變更信息。重做日志文件的特點是
可覆蓋,循環(huán)寫。重做日志文件頻繁切換會對數(shù)據(jù)庫產(chǎn)生較大的性能
影響。
resize 重做日志文件
alter database resize logfile ‘/dm8/data/DAMENG/DAMENG01.log’ TO
300;
alter database resize logfile ‘/dm8/data/DAMENG/DAMENG02.log’ TO
300;
新增重做日志文件:
alter database add logfile ‘/dm8/data/DAMENG/DAMENG03.log’ size
300;
注意:重做日志文件不能被刪除,所有日志文件大小需要一致。
歸檔日志文件
就是重做日志文件的副本,用來做數(shù)據(jù)庫恢復(fù)。
開啟歸檔:
開啟歸檔:
co命令行開歸檔
SQL> alter database mount;
SQL> alter database add archivelog ‘type=local,dest=/dm8/arch,file_size=100,space_limit=0’;
SQL> alter database archivelog;
SQL> alter database open;
SQL> select name,arch_mode from v$database;
行號NAME ARCH_MODE
1 DAMENG Y
圖形化歸檔
備份文件
以.bak 為擴展名的文件,備份文件就是數(shù)據(jù)庫在某一個時間點的副
本。.meta 元數(shù)據(jù)文件(備份集的信息),.bak 數(shù)據(jù)備份文件(真實
的數(shù)據(jù))
跟蹤日志文件
跟蹤日志文件記錄的是系統(tǒng)各會話執(zhí)行的sql 語句的信息,主要是錯
誤的信息、性能問題。跟蹤日志文件默認是關(guān)閉的。SVR_LOG
事件日志文件
記錄的是數(shù)據(jù)庫運行期間產(chǎn)生的關(guān)鍵性事件:數(shù)據(jù)庫的啟動、關(guān)閉、
IO 錯誤、內(nèi)存申請失敗。
邏輯結(jié)構(gòu)
頁(塊):默認為8k(8192 字節(jié)),支持4k、8k、16k、32k。數(shù)據(jù)
頁是數(shù)據(jù)庫最小的分配單元。包含了頁頭信息,數(shù)據(jù),空閑空間,行
偏移數(shù)組。Filefactor
簇:簇是一組連續(xù)的數(shù)據(jù)頁組成,默認為16 個頁,支持16、32 個頁,
總是在一個數(shù)據(jù)文件中。
段:是簇的上級邏輯單元,段是可以跨多個數(shù)據(jù)文件的。段分為數(shù)據(jù)
段(表段、索引段),臨時段,回滾段。
select * from user_segments;
表空間:可以擁有一個或多個數(shù)據(jù)文件,一個數(shù)據(jù)文件只能屬于一個
表空間。
8.1 查看表空間
脫機狀態(tài)
聯(lián)機或脫機
用戶管理分為三塊:用戶、權(quán)限、角色
select username,account_status from dba_users;
9.3.1 命名原則
字符開頭,a-z,0-9,$#_ ;長度為 128 個字符 ;權(quán)限分配:系統(tǒng)權(quán)限、對象權(quán)限、角色 ;存儲位置:表空間(默認main) ;密碼策略:
PWD_POLICY 設(shè)置系統(tǒng)默認口令策略。
PWD_POLICY: 設(shè)置系統(tǒng)默認口令策略。0: 無策略;1: 禁止與用戶名相同;2: 口令長度不小于9;4: 至少包含一個大寫字母(A-Z);8 :至少包含一個數(shù)字(0-9);16:至少包含一個標(biāo)點符號(英文輸入法狀態(tài)下,除“和空格外的所有符號;若為其他數(shù)字,則表示配置值的和,如3=1+2,表示同時啟用第1項和第2項策略。當(dāng)COMPATIBLE_MODE=1時,PWD_POLICY的實際值均為0
3=1+2 7=4+2+1
PWD_POLICY 值數(shù)據(jù)庫重啟生效
圖形console 工具更改
COMPATIBLE_MODE 是否兼容其他數(shù)據(jù)庫模式(靜態(tài)參數(shù))
。0:不兼容,1:兼容SQL92標(biāo)準(zhǔn),2:兼容ORACLE,3:兼容MS SQL SERVER,4:兼容MYSQL。
9.4創(chuàng)建 test 表空間
注意:表空間名要用大寫(建用戶一樣)
路徑 /dm8/data/DAMENG/TESST01.DBF 大小默認 自動擴展開啟 擴展尺寸(MB)1 上限(MB )500
9.5.1 圖形建用戶
密碼不小于9位,表空間選擇TEST表空間,可以修改。更改用戶的默認表空間、更改密碼、查看用戶的狀態(tài) 、鎖定 test 用戶、解鎖 test 用戶、撤回權(quán)限、刪除用戶。
創(chuàng)建用戶會自動創(chuàng)建一個與用戶名同名的模式,一個用戶可以對應(yīng)多
個模式。
大寫
DM 數(shù)據(jù)庫執(zhí)行 sql 腳本:
先建test1表
; exit
授權(quán)
start /home/dmdba/test1.sql
start /home/dmdba/test1.sql
清空表
主鍵約束:非空+唯一,一個表只能有一個主鍵,設(shè)計主鍵盡量的避
開業(yè)務(wù)邏輯的列
外鍵約束:
SQL> create table test4 (id int foreign key references test3(id));
SQL> drop table test3;
檢查約束
SQL> create table test5(id int check(id>=5));
查看約束:
啟用約束 禁用
創(chuàng)建簡單的視圖:
create view test5.emp_v as
select
employee_id,employee_name,salary,department_id
from
dmhr.employee where department_id=1005;
查詢視圖
通過 manager 工具
也可以查看視圖 all_views
創(chuàng)建索引
查看索引信息:
select * from user_indexes;
查看 sql 執(zhí)行計劃
備份主要有:物理備份和邏輯備份 ,物理備份:分為聯(lián)機備份和脫機備份;完全備份和增量備份。
物理備份:冷備:不需要開啟歸檔,針對整庫做備份
需要開啟 dmap 服務(wù),需要關(guān)閉數(shù)據(jù)庫實例
1、 console 工具備份
2、 用 dmrman 工具備份 只支持冷備
RMAN> backup database ‘/dm8/data/DAMENG/dm.ini’ backupset
‘/dm8/bakcup’;
檢查備份集
RMAN> check backupset ‘/dm8/backup’;
熱備:
需要開啟歸檔,數(shù)據(jù)庫需要聯(lián)機
可以備份數(shù)據(jù)庫、表空間、表、歸檔日志文件
查看數(shù)據(jù)庫歸檔模式:
SQL> select arch_mode from v$database;行號 歸檔模式
ARCH_MODE
1
Y
利用 manager 工具做熱備
增量備份:Disql 工具:
整庫備份:
backup database full to “full02” backupset ‘/dm8/backup/rb’;
增量備份:
手動指定工作目錄就能看的到了
表空間備份:
表備份:
歸檔日志備份:
物理還原:
新建作業(yè) 1,每周三,每周日 22:00 做全備call
增備
選目錄基于哪一個全備做的
Linux 環(huán)境配置 odbc
解壓縮
用 root 配置
[root@localhost home]# tar -xvf unixODBC-2.3.0.tar.gz解壓縮
[root@localhost home]# cd unixODBC-2.3.0/
[root@localhost unixODBC-2.3.0]# ./configure
[root@localhost unixODBC-2.3.0]# make 編譯
[root@localhost unixODBC-2.3.0]# make install 安裝
[root@localhost unixODBC-2.3.0]# odbcinst -j 看版本
Cat
配置/usr/local/etc/odbcinst.ini /usr/local/etc/odbc.ini測試連接
[dm8]
description = DM ODBC DSND
Driver = DM8 ODBC DRIVER
SERVER = localhost
UID = SYSDBA
PWD = dameng123
TCP_PORT = 5236
[DM8 ODBC DRIVER]
Description = ODBC DRIVER FOR DM8
DRIVER = /dm8/bin/libdodbc.so
用 dmdba 賬戶
isql dm8
總結(jié)
以上是生活随笔為你收集整理的达梦数据库DM8 DCA认证学习笔记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 九点图
- 下一篇: 搭建企业级微信公众号管理平台(三)---