mysqldump mysqldump -u root -d -R --add-drop-table basedata >basedata.sql -d只有表結構即列信息,無內容即行信息 · --no-data, -d Do not write any table row information ( ...
mysqldump
這一段代碼太不優化了,多餘-重覆
不需要sed來添加行,只需要加入 --add-drop-database就可以了
有--database或-A,添加--add-drop-database才有效。
還是要多看看 #man mysqldump手冊頁。瞭解具體需求,才有針對性。
mysqldump -u root -d -R --add-drop-table basedata >basedata.sql sed -i '1i\use basedata;' basedata.sql sed -i '1i\create database basedata;' basedata.sql sed -i '1i\drop database if exists basedata;' basedata.sql mysqldump -u root --add-drop-table basedata industry>>basedata.sql mysqldump -u root --add-drop-table basedata data_dictionary>>basedata.sql mysqldump -u root --add-drop-table --extended-insert=false basedata tb_sequence>>basedata.sql
-e, --extended-insert,長INSERT,多row在一起批量INSERT,提高導入效率,和沒有開啟 -e 的備份導入耗時至少相差3、4倍,預設開啟;用--extended-insert=false關閉。強烈建議開啟,通過下麵的測試比較就會明白為什麼了。 (1)預設方式導出,也即--extended-insert=true -d只有表結構即列信息,無內容即行信息 · --no-data, -d Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only the CREATE TABLE statement for the table (for example, to create an empty copy of the table by loading the dump file). · --routines, -R Include stored routines (procedures and functions) for the dumped databases in the output. Use of this option requires the SELECT privilege for the mysql.proc table. The output generated by using --routines contains CREATE PROCEDURE and CREATE FUNCTION statements to re-create the routines. However, these statements do not include attributes such as the routine creation and modification timestamps. This means that when the routines are reloaded, they will be created with the timestamps equal to the reload time.
mysqlbinlog
因為每次操作的時間和“位置”都會被記錄下來。所以要想還原數據有兩種途徑通過“時間”或“位置”。
[root@manage mysql]# pwd /var/lib/mysql [root@manage mysql]# ls cloud ibdata1 mysql-bin.000001 mysql-bin.000005 mysql-bin.000009 mysql-bin.000013 cloudbridge ib_logfile0 mysql-bin.000002 mysql-bin.000006 mysql-bin.000010 mysql-bin.index cloud_usage ib_logfile1 mysql-bin.000003 mysql-bin.000007 mysql-bin.000011 mysql.sock fss mysql mysql-bin.000004 mysql-bin.000008 mysql-bin.000012 spauth [root@manage mysql]# mysqlbinlog mysql-bin.000013 |more