간략한 소개
1 부 : 상단에 쓰기
오래 전에, 내가 생산 MySQL 데이터베이스 백업 스크립트의 전체 라이브러리를 작성, 기본 저장 프로 시저에 대해 --help mysqldump에 예정이다 만약 내가 근거에 저장 프로 시저를 백업 할 -R 매개 변수를 추가 할 경우 동료가 나에게 물었다 오늘이 백업은 false입니다.
루틴 FALSE
전체 생산 MySQL 데이터베이스 백업 스크립트
현실
1 부 : 상단에 쓰기
나는 보통 세 개의 매개 변수로 백업
- 단일 트랜잭션 데이터 -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 : 다른 백업 스크립트를 수행
매개 변수는
- 단일 트랜잭션 데이터 -A --master = 2
- 단일 트랜잭션 -A -R --master 데이터 = 2
Part4 : 비교 SQL 파일
-R 옵션은 -R이 기록되지 증가하지 않았다 SQL 문이 저장 프로 시저를 만듭니다 기록 추가 그것은 파일에서 찾을 수 있습니다.
-- 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 즉를 도입하지 않고, 리눅스 환경, 무거운 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의를 포함하는 저자 덕분에 -A 전체 데이터베이스 백업 전략, 즉, 저장 프로세스는 백업 할 수 있습니다. -R 매개 변수는 일반적으로 하나 또는 여러 개의 백업 백업에 사용됩니다. 펜이 있기 때문에 준비 시간의 수준에 의해 제한됩니다 매우 짧고, 텍스트가 불가피 오류 또는 부정확, 부적절 독자의 비판을 촉구 할 것이다.