Mysql備份--mysqldump&outfile

來源:互聯網
上載者:User

標籤:

1.備份工具
mysqldump 用戶端和伺服器端都能用
select outfile 只能寫到伺服器端

2.按表單位備份
  a.單個表備份

mysqldump -uusername -p database table1 >tableback.sqlmysql> select * into outfile ‘D:\someBookes\mysql\pracitce\mysql_user.sql‘ fields terminated by ‘,‘    -> optionally enclosed by ‘"‘ escaped by ‘#‘    -> lines terminated by ‘\n‘ from user;Query OK, 7 rows affected (0.07 sec)mysql> exitBye

小插曲:windows作業系統的下反斜線會被忽略,檔案直接建立到D盤的根目錄了。用正斜杆才能建立到對應的目錄,如下:

mysql> use mysql;Database changedmysql> select * into outfile ‘D:/someBookes/mysql/pracitce/mysql_user.sql‘ fields terminated by ‘,‘    -> optionally enclosed by ‘"‘ escaped by ‘#‘    -> lines terminated by ‘\n‘ from user;Query OK, 7 rows affected (0.00 sec)mysql>

這樣只能將資料匯出到伺服器端,如何將資料寫入用戶端呢?只能封裝下SQL 寫到用戶端
mysql -h192.168.1.119 -uroot -ppasswd -e"select * from std.ygxxwh_b0;" > D:/someBookes/mysql/pracitce/stdd.sql

  b.多個表備份
  mysqldump -uusername -p database table1 table2 >tablesback.sql

3.按資料庫單位備份
  a.備份單個資料庫
  mysqldump -uusername -p --database database1 >databaseback.sql
  b.備份多個資料庫
  mysqldump -uusername -p --database database1 database2 >databasesback.sql

4.mysqldump常用參數
--add-drop-database Add a Drop database before each create.
--add-drop-tableAdd a Drop table before each create.(預設開啟)
--hex-blobDump binary strings (BINARY,VARBINARY,BLOB) in hexadecimal format.
--no-data只匯出表結構
--single-transaction Create a consistent snapshot by dumping all tables in a single transaction.Works only for tables stored in storage engines which support multiversioning(INNODB).

 

5.恢複工具

由於Mysql的備份都是以SQL的形式產生的,運行備份的指令碼即可。

6.Mysql的記錄檔系統的組成
a.錯誤記錄檔:記錄啟動、運行或停止是Mysql出現的問題。
b.通用日誌:記錄建立的用戶端串連和執行的SQL語句。
c.二進位日誌:記錄所有更改資料的語句。還用於複製。
d.慢查詢日誌:記錄所有執行時間超過long_query_time秒的所有查詢或不使用索引的查詢。
e.Innodb日誌:innodb redo log

預設情況下所有日誌建立於mysql資料目錄中
可以通過重新整理日誌來強制Mysqld關閉和重新開啟記錄檔
執行flush logs 或者 mysqladmin flush-logs 或 mysqladmin refresh 時,日誌被老化。

Mysql備份--mysqldump&outfile

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.