您的位置:極速下載站→ 資訊首頁(yè) → 系統(tǒng)教程 → 系統(tǒng)資訊 → 講解linux下mysal備份的幾種方法教程
時(shí)間:2019-09-16 14:45:07 作者:無(wú)名 瀏覽量:41
大家好,小編是個(gè)電腦軟件控,注意這里是ubuntu11.04版別mysql 5.1 。windows下的估量有區(qū)別。。自己研討去吧。
1.登錄mysql后用BACKUP、RESTORE指令不引薦使用,后邊的版別可能會(huì)移除。。所以還是別用了!
2。用mysqldump指令備份。假設(shè)在firstdb下有個(gè)test 表。則運(yùn)轉(zhuǎn)
mysqldump -uUERNAME -pPASSWord-hHOSTNAME firstdb test > test.sql
登錄后mysql后運(yùn)轉(zhuǎn):drop table test ;
現(xiàn)在康復(fù) : mysql -uUSRNAME-pPASSWord -hHOSTNAME firstdb < test.sql
這樣本來(lái)的test就康復(fù)了。。
當(dāng)然mysqldump很多參數(shù)。。自己man去吧!
<!--[if !supportLists]-->3、<!--[endif]-->用select into 做備份
講解linux下mysal備份的幾種方法教程圖2
登錄mysql后運(yùn)轉(zhuǎn):select * from test into outfile \\\"test.dat\\\";
清空表:truncate test ;
康復(fù)能夠: load data infile \\\"test.dat\\\" into table test ;
當(dāng)然還能夠用mysqlimport指令代替load data 。。在bash下運(yùn)轉(zhuǎn):
mysqlimport -uUSERNAME -pPASSWROD-hHOSTNAMEfirstdbtest.dat ;
這樣就能夠康復(fù)了。。
不過(guò)注意在linux下的權(quán)限問(wèn)題。。這個(gè)不解說(shuō)。。mysql的權(quán)限辦理用戶是一個(gè)系統(tǒng)用戶--mysql,具體檢查相關(guān)linux 權(quán)限的書(shū)籍!
4.使用mysqlhotcopy指令
用法和mysqlimport類似。。這是一個(gè)perl腳本。。檢查help就會(huì)用了。。
5.使用二進(jìn)制更新的日志文件康復(fù)數(shù)據(jù)到近期方位。
這個(gè)要求翻開(kāi)log-bin選項(xiàng),在/etc/mysql/my.cnf 下設(shè)置。。使用正則表達(dá)式很簡(jiǎn)單就能夠找到log-bin選項(xiàng),把注釋去了就能夠了。當(dāng)然也能夠自己加上。
然后使用mysqlbinlog XXXX-bin.XXX 就能夠康復(fù)了。。默認(rèn)應(yīng)該是放在/var/log/mysql 。。自己使用find指令找。。
講解linux下mysal備份的幾種方法教程圖3
6最后一種方法不多說(shuō)。。直接把整個(gè)數(shù)據(jù)庫(kù)復(fù)制。。。使用cp 指令復(fù)制到其他目錄或文件系統(tǒng)。?祻(fù)也簡(jiǎn)單。。。
4個(gè)timeout都是為了防止某一個(gè)鏈接長(zhǎng)時(shí)間占用一數(shù)據(jù)庫(kù)的描述符,又不干事情,或者網(wǎng)絡(luò)有問(wèn)題沒(méi)有釋放
這個(gè)描述符,線程阻塞種種資源浪費(fèi)的情況.我們要主動(dòng)的\"卡\"掉對(duì)端!
首先看看這4個(gè)timeout在mysql5.1手冊(cè)里的英文解釋:
connect_timeout
The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake.
interactive_timeout
The number of seconds the server waits for activity on an interactive connection before closing it.
wait_timeout
The number of seconds the server waits for activity on a noninteractive connection before closing it.
net_read_timeout
The number of seconds to wait for more data from a connection before aborting the read.
net_write_timeout
The number of seconds to wait for a block to be written to a connection before aborting the write.
從意思上可以理解為
connect_timeout在獲取連接階段(authenticate)起作用,
interactive_timeout和wait_timeout在連接空閑階段(sleep)起作用,
net_read_timeout和net_write_timeout在連接繁忙階段(query)起作用。