如何用mysqldump進(jìn)行全量和時(shí)間點(diǎn)備份
mysqldump在mysql中用于邏輯備份,雖然速度不快,但非常靈活,有很多功能,靈活使用的化絕對(duì)是利器。
首先思考一個(gè)問(wèn)題,mysql為什么要備份,主要還是數(shù)據(jù)安全性,比如主庫(kù)掛了,數(shù)據(jù)不小心被刪除了,所以全量備份非常重要。
是從主庫(kù)還是副庫(kù)進(jìn)行全量備份呢?
1:從主庫(kù)
主庫(kù)比較重要,但其實(shí)備份的時(shí)候并不會(huì)影響數(shù)據(jù)庫(kù)
mysqldump --host= --user= --password= --single-transaction --master-data=1 --flush-logs --databases >~/db.log
—single-transaction 參數(shù)能夠報(bào)紙一致性讀,不會(huì)鎖表,也就是備份的時(shí)候不影響數(shù)據(jù)更新。
it dumps the consistent state of the database at the time when START TRANSACTION was issued without blocking any applications.
因?yàn)橐恢滦宰x,能夠保證coordinates點(diǎn)的位置,即使備份時(shí)間很久,也能得出正確的同步位置點(diǎn)。
While a —single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates)
—master-data參數(shù)也很重要,導(dǎo)出的語(yǔ)句會(huì)包含CHANGE MASTER TO語(yǔ)句,包括備份語(yǔ)句同步到的二進(jìn)制文件和位置點(diǎn)。
Use this option to dump a master replication server to produce a dump file that can be used to set upanother server as a slave of the master. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave.
—flush-logs會(huì)強(qiáng)制重新生成一個(gè)新的二進(jìn)制文件,這樣恢復(fù)的時(shí)候會(huì)比較方便。
2:從副庫(kù)
感覺(jué)上從副庫(kù)備份更安全。
mysqldump --host=--user= --password= --dump-slave=1 --flush-logs --apply-slave-statements --include-master-host-port --databases >~/db.log;
— dump-slave和—master-data參數(shù)很類似:
This option is similar to —master-data except that it is used to dump a replication slave server to produce a dump file that can be used to set up another server as a slave that has the same master as the dumped server. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped slave's master. These are the master server coordinates from which the slave should start replicating.
記住一點(diǎn)它獲取的是主庫(kù)的bin log coordinates(不是備份庫(kù)的)
—dump-slave causes the coordinates from the master to be used rather than those of the dumped server
dump出來(lái)的語(yǔ)句會(huì)包含 — Position to start replication or point-in-time recovery from。
—apply-slave-statements會(huì)讓dump語(yǔ)句中自動(dòng)包含start和stop slave語(yǔ)句。—include-master-host-port包含主庫(kù)的連接信息。
必須記住一點(diǎn),即使有—single-transaction語(yǔ)句,—dump-slave也會(huì)暫停mysql同步,也就是備份庫(kù)的數(shù)據(jù)是落后于主庫(kù)的,所以一般自動(dòng)化腳本在備份的時(shí)候會(huì)先摘除備份庫(kù)。
This option causes mysqldump to stop the slave SQL thread before the dump and restart it again after.
3:如何進(jìn)行時(shí)間點(diǎn)恢復(fù)
沒(méi)有實(shí)戰(zhàn)過(guò),首先基于最近的一次全量備份進(jìn)行恢復(fù),然后將后續(xù)的binlog文件導(dǎo)入(如果這些文件還在的話),所以副庫(kù)最好也備份binlog語(yǔ)句。
如果數(shù)據(jù)被誤刪除了,將備份點(diǎn)(—flush-logs發(fā)揮作用了)到今天凌晨的binlog語(yǔ)句導(dǎo)入進(jìn)來(lái),或者找到安全的binlog位置點(diǎn)進(jìn)行恢復(fù)。至于如何跳過(guò)“危險(xiǎn)語(yǔ)句”是比較難控制的。
以上就是如何用mysqldump進(jìn)行全量和時(shí)間點(diǎn)備份的詳細(xì)內(nèi)容,更多關(guān)于mysqldump進(jìn)行全量和時(shí)間點(diǎn)備份的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- mysqldump你可能不知道的參數(shù)
- MySQL5.7 mysqldump備份與恢復(fù)的實(shí)現(xiàn)
- linux使用mysqldump+expect+crontab實(shí)現(xiàn)mysql周期冷備份思路詳解
- MySql使用mysqldump 導(dǎo)入與導(dǎo)出方法總結(jié)
- MySQL之mysqldump的使用詳解
- docker 使用mysqldump命令備份導(dǎo)出項(xiàng)目中的mysql數(shù)據(jù)
- MySQL數(shù)據(jù)遷移使用MySQLdump命令
- PHP定時(shí)備份MySQL與mysqldump語(yǔ)法參數(shù)詳解
- mysql備份腳本 mysqldump使用方法詳解
- 詳解 linux mysqldump 導(dǎo)出數(shù)據(jù)庫(kù)、數(shù)據(jù)、表結(jié)構(gòu)
- 詳談mysqldump數(shù)據(jù)導(dǎo)出的問(wèn)題
- MySQL官方導(dǎo)出工具mysqlpump的使用
相關(guān)文章
MYSQL(電話號(hào)碼,身份證)數(shù)據(jù)脫敏的實(shí)現(xiàn)
在日常開(kāi)發(fā)需求中會(huì)經(jīng)常遇到數(shù)據(jù)脫敏處理,比如身份證號(hào)、手機(jī)號(hào),需要使用*進(jìn)行部分替換顯示。這樣能使敏感隱私信息在一定程度上得到保護(hù)。本文就來(lái)介紹一下2021-05-05介紹使用WordPress時(shí)10個(gè)常用的MySQL查詢
這篇文章主要介紹了介紹使用WordPress時(shí)10個(gè)常用的MySQL查詢,許多用戶在使用WordPress時(shí)選擇使用MySQL,本文的整理對(duì)于剛剛上手的用戶來(lái)說(shuō)非常有用,需要的朋友可以參考下2015-04-04MySQL8數(shù)據(jù)庫(kù)安裝及SQL語(yǔ)句詳解
本文詳細(xì)講解了MySQL8數(shù)據(jù)庫(kù)安裝及SQL語(yǔ)句用法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02Windows下MySQL?8.0.29?安裝和刪除圖文教程
這篇文章主要為大家詳細(xì)介紹了Windows下MySQL?8.0.29?安裝和刪除圖文教程,文中安裝步驟介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07mysql重裝后出現(xiàn)亂碼設(shè)置為utf8可解決
mysql重裝后出現(xiàn)亂碼解決辦法:只能在配置文件中將database 和 server 字符集 設(shè)置為utf8 ,否則不起作用,具體如下感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-07-07Mysql事務(wù)隔離級(jí)別原理實(shí)例解析
這篇文章主要介紹了Mysql事務(wù)隔離級(jí)別原理實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03MySQL數(shù)據(jù)庫(kù)備份與恢復(fù)方法
網(wǎng)站數(shù)據(jù)對(duì)我們對(duì)站長(zhǎng)來(lái)說(shuō)都是最寶貴的,我們平時(shí)應(yīng)該養(yǎng)成良好的備份數(shù)據(jù)的習(xí)慣。2010-12-12