摘要:數(shù)據(jù)庫數(shù)據(jù)備份與恢復(fù)通過備份數(shù)據(jù)庫,包含和以及的工具中也有類似的功能可以實現(xiàn)數(shù)據(jù)庫的備份備份數(shù)據(jù)庫使用命令備份多個數(shù)據(jù)庫備份所有數(shù)據(jù)庫。
數(shù)據(jù)庫數(shù)據(jù)備份與恢復(fù)
通過CMD備份數(shù)據(jù)庫,包含Mysql和OracleMySQL: 備份數(shù)據(jù)庫:
PS: PLSQL以及Navicat 的工具中也有類似的功能可以實現(xiàn)數(shù)據(jù)庫的備份
使用mysqldump命令 :mysqldump -uroot -proot [dbname]> f:/backup/backupfile.sql;
備份多個數(shù)據(jù)庫:mysqldump -u username -p --databases [dbname1] [dbname2]> backupfile.sql;
備份所有數(shù)據(jù)庫:mysqldump -u username -p --all-databases > backupfile.sql。
說明: 默認在電腦的當前用戶目錄下(例:C:UsersLEGION)問題:
使用mysqldump導(dǎo)出時提示 :Warning:A partial dump from a server that has GTIDs :
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don"t want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
原因:GTID是5.6以后,加入了全局事務(wù) ID (GTID) 來強化數(shù)據(jù)庫的主備一致性,故障恢復(fù),以及容錯能力。
官方給的:A global transaction identifier (GTID) is a unique identifier created and associated with each transaction committed on the server of origin (master). 所以可能是因為在一個數(shù)據(jù)庫里面唯一,但是當導(dǎo)入其他的庫就有可能重復(fù)。 - 解決:按照提示添加:`--set-gtid-purged=off `或`–gtid-mode=OFF` ; 即:`mysqldump -uroot -set-gtid-purged=off -p mydbname>fbackupfile.sql`。
直接使用mysql命令:mysql -u root -p [dbname] < backup.sq;
Oracle:更多參考
mysqldump數(shù)據(jù)導(dǎo)出問題和客戶端授權(quán)后連接失敗問題
學(xué)會4種備份MySQL數(shù)據(jù)庫
導(dǎo)出(exp):
exp 用戶名/密碼@IP/ORCL file=e:ackupfile.dmp owner=(用戶名)
例:exp myName/myPwd@127.0.0.1/ORCL file=e:ackupfile.dmp owner=(myName)
導(dǎo)入(imp):
imp 用戶名/密碼@IP/ORCL ignore=y full=y file=e: