新聞中心
在日常維護(hù)工作當(dāng)中經(jīng)常會(huì)需要對(duì)數(shù)據(jù)進(jìn)行導(dǎo)出操作,而mysqldump是導(dǎo)出數(shù)據(jù)過程中使用非常頻繁的一個(gè)工具;它自帶的功能參數(shù)非常多,下面為大家詳細(xì)講解一下mysqldump的使用方法。

一、mysqldump使用方法
(1)、備份單個(gè)數(shù)據(jù)庫或數(shù)據(jù)庫中的部分表,使用mysqldump導(dǎo)出之前,會(huì)鎖定表的寫操作,當(dāng)數(shù)據(jù)導(dǎo)出完成后,鎖被釋放。
shell> mysqldump [options] db_name [table_name]
(2)、備份指定的一個(gè)或多個(gè)數(shù)據(jù)庫
shell> mysqldump [options] --database DB1 [DB2,DB3,...]
shell> mysqldump [options] -B DB1 [DB2,DB3,...]
(3)、備份服務(wù)器上的所有數(shù)據(jù)庫
shell> mysqldump [options] --all-database
shell> mysqldump [options] -A
二、mysqldump主要參數(shù)
-u,--user=username # 指定用戶名
-p,--password=password # 指定密碼
-h,--host=hostname # 指定服務(wù)器ip
-P,--port=port # 指定連接端口
--add-drop-database # 在每個(gè)數(shù)據(jù)庫創(chuàng)建語句前加上drop database語句
--add-drop-table # 在每個(gè)表創(chuàng)建語句前加上drop table語句
-n,--no-create-db # 不包括數(shù)據(jù)庫的創(chuàng)建語句
-t,--no-create-info # 不包括數(shù)據(jù)表的創(chuàng)建語句
-d,--no-data # 不包括數(shù)據(jù)
--compact # 輸出更為簡(jiǎn)潔,不包括各種注釋語句
-c,--complete-insert # 使輸出文件中的insert語句包括字段名稱,默認(rèn)不包括字段名稱
-F,--flush-logs # 備份前刷新日志
-l,--lock-tables # 備份期間對(duì)所有表加鎖
--help mysqldump # 命令幫助
三、字符集選項(xiàng)
–default-character-set選項(xiàng)可以設(shè)置導(dǎo)出的客戶端字符集,這個(gè)選項(xiàng)在導(dǎo)出數(shù)據(jù)庫的時(shí)候非常重要,如果客戶端字符集和數(shù)據(jù)庫字符集不一致,數(shù)據(jù)庫在導(dǎo)出的時(shí)候就可能需要字符集轉(zhuǎn)換,將數(shù)據(jù)庫字符集轉(zhuǎn)換為客戶端字符集,講過轉(zhuǎn)換后的數(shù)據(jù)可能變成亂碼或“?”等特殊字符,使得備份文件無法恢復(fù)。
四、mysqldump實(shí)戰(zhàn)
(1)、備份test數(shù)據(jù)庫下的city表
# mysqldump -uroot -p test city > city.txt
(2)、由于客戶端和服務(wù)器的字符集不一致,導(dǎo)出文件變成亂碼,導(dǎo)致無法導(dǎo)入,見如下截圖:
# mysqldump -uroot -p --default-character-set=latin1 test city > city.txt
(3)、使用-c參數(shù),使得insert into語句中增加了表的列名,見如下截圖:
# mysqldump -uroot -p -c test city > city.txt
(4)、加了-d參數(shù),使得mysqldump只導(dǎo)出了city表的表結(jié)構(gòu),表數(shù)據(jù)未被導(dǎo)出,見如下截圖:
# mysqldump -uroot -p -d test city > city.txt
文章名稱:通過mysqldump導(dǎo)出數(shù)據(jù)庫(表)
本文網(wǎng)址:http://m.fisionsoft.com.cn/article/dpihjgs.html


咨詢
建站咨詢
