簡単な紹介
パート1: トップに書きます
やがて、私は本番MySQLデータベースのバックアップスクリプトのライブラリ全体を書いて、デフォルトでは、ストアド・プロシージャについて--help mysqldumpをすることになっている場合、私は敷地内にストアドプロシージャをバックアップするために、-Rパラメータを追加したい場合は同僚が私に尋ねた、今日がありますバックアップはfalseです。
ルーチンFALSE
フル生産MySQLデータベースのバックアップスクリプト
リアル
パート1: トップに書きます
私は通常、三つのパラメータにバックアップ
--single-トランザクション-A --master-データ= 2
つまり防止ロック、データベースの完全バックアップとコピーの情報を記録します
誰かが単一のライブラリを復元する方法を尋ねましたか?会場は缶
ライブラリとMySQLデータベースのバックアップからの完全なテーブルを復元します。
パート2: ストアドプロシージャの作成
[root@HE3 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database helei;
Query OK, 1 row affected (0.02 sec)
mysql> use helei;
Database changed
mysql> create table helei(
-> id int(10) unsigned NOT NULL AUTO_INCREMENT,
-> c1 int(10) NOT NULL DEFAULT '0',
-> c2 int(10) unsigned DEFAULT NULL,
-> c5 int(10) unsigned NOT NULL DEFAULT '0',
-> c3 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-> c4 varchar(200) NOT NULL DEFAULT '',
-> PRIMARY KEY(id),
-> KEY idx_c1(c1),
-> KEY idx_c2(c2)
-> )ENGINE=InnoDB ;
Query OK, 0 rows affected (0.02 sec)
mysql> delimiter $$
mysql> drop procedure if exists `insert_helei` $$
and()*row_num),now(),repeat('su', floor(rand()*20)));
set i = i+1;
END while;
end$$Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create procedure `insert_helei`(in row_num int )
-> begin
-> declare i int default 0;
-> while i < row_num do
-> insert into helei(c1, c2, c5,c3, c4) values( floor(rand()*row_num),floor(rand()*row_num),floor(rand()*row_num),now(),repeat('su', floor(rand()*20)));
-> set i = i+1;
-> END while;
->
-> end$$
Query OK, 0 rows affected (0.00 sec)
mysql>
复制代码
その3: 異なるバックアップスクリプトを実行します
パラメータは、
--single-トランザクション-A --master-データ= 2
--single-トランザクション-A -R --master-データ= 2
その4: 比較SQLファイル
これは、ファイルで見つけることができ-Rを追加するSQL文は、ストアドプロシージャを作成し記録し、-Rが記録されていない増加しませんでした。
-- Dumping routines for database 'helei'
--
/*!50003 DROP PROCEDURE IF EXISTS `insert_helei` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_helei`(in row_num int )
begin
declare i int default 0;
while i < row_num do
insert into helei(c1, c2, c5,c3, c4) values( floor(rand()*row_num),floor(rand()*row_num),floor(rand()*row_num),now(),repeat('su', floor(rand()*20)));
set i = i+1;
END while;
end ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
复制代码
検証
パート1: 確認してください
バックアップファイルは、SQLプロシージャに格納されているパラメータを作成せずに、-R、すなわちを導入することなく、Linux環境、重いMySQLを空に
[root@HE3 ~]# mysql -uroot -p < Master_db_201612051722.sql
Enter password:
[root@HE3 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use helei;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from helei;
Empty set (0.00 sec)
mysql> call insert_helei(5);
Query OK, 1 row affected (0.01 sec)
mysql> select * from helei;
+----+----+------+----+---------------------+------------------------------------+
| id | c1 | c2 | c5 | c3 | c4 |
+----+----+------+----+---------------------+------------------------------------+
| 1 | 1 | 2 | 0 | 2016-12-05 17:51:37 | sususususususususususu |
| 2 | 2 | 1 | 0 | 2016-12-05 17:51:37 | sususususususususususususususususu |
| 3 | 4 | 1 | 3 | 2016-12-05 17:51:37 | sususususususususususu |
| 4 | 3 | 2 | 3 | 2016-12-05 17:51:37 | sususususususususususu |
| 5 | 0 | 2 | 4 | 2016-12-05 17:51:37 | sususususususususu |
+----+----+------+----+---------------------+------------------------------------+
5 rows in set (0.00 sec)
mysql>
复制代码
それも、-Rパラメータを添加せず、それはまだ先に作成したストアドプロシージャを呼び出すことができることを見出しました。
-概要 -
mysql.procストアドプロシージャは、テーブルに格納され、MySQLを含む著者のおかげ-Aデータベースの完全バックアップ戦略、即ち、保存処理は、バックアップされるべきです。-Rパラメータは、一般に、単一または複数のバックアップのバックアップのために使用されています。ペンがあるので 準備時間のレベルによって制限されている非常に短く、テキストは必然的にいくつかの誤りや不正確になり、不備は、読者の批判を促します。