[MySQL] MySQL 백업 및 복구
작성일 13-03-28 09:48
페이지 정보
작성자서방님 조회 160회 댓글 0건본문
MySQL 백업 및 복구
- MySQL 디렉토리 전체를 압축 백업하기
mysql dir : /var/lib (데이터베이스 디렉토리)
[root@byungun lib]# tar cvfpz mysql_dir_tar.gz /var/lib/mysql
- 특정 데이터베이스 백업과 복구
백업 형식 : mysqldump -u DB계정명 -p DB명 > 저장할파일명
복구 형식 : mysql -u DB계정명 -p DB명 < 저장할파일명
# mysql DB 백업
[root@byungun DB_backup]# mysqldump -u root -p mysql > mysqldb.sql
Enter password:
# mysql DB 생성
[root@byungun DB_backup]# mysqladmin -u root -p create mysql
Enter password:
# mysql DB 복구
[root@byungun DB_backup]# mysql -u root -p mysql < mysqldb.sql
Enter password:
- 특정 데이터베이스의 특정 테이블 백업과 복구
백업 형식 : mysqldump -u DB계정명 -p DB명 Table명 > 저장할파일명
복구 형식 : mysql -u DB계정명 -p DB명 < 저장할파일명
# mysql DB Table 백업
[root@byungun DB_backup]# mysqldump -u root -p testdb testtable > testtable_table.sql
Enter password:
# mysql DB Table 복구
[root@byungun DB_backup]# mysql -u root -p testdb < testtable_table.sql
Enter password:
- 여러 개의 데이터베이스 한 번에 백업과 복구
백업 형식 : mysqldump -u DB계정명 -p --databases [옵션] DB1 DB2 DB3 > 저장할파일명
복구 형식 : mysql -u DB계정명 -p < 저장할파일명
# mysql 여러 개의 DB 백업
[root@byungun DB_backup]# mysqldump -u root -p --databases tempdb testdb > various_db.sql
Enter password:
# mysql DB 복구
[root@byungun DB_backup]# mysql -u root -p < various_db.sql
Enter password:
- MySQL 전체 데이터베이스 백업과 복구
백업 형식 : mysqldump -u DB계정명 -p --all-databases > 저장할파일명
복구 형식 : mysql -u DB계정명 -p < 저장할파일명
[root@byungun DB_backup]# mysql -u root -p --all-databases > mysql_alldb.sql
Enter password:
=============================================================================
MySQL 백업 및 복구 - MySQL 디렉토리 전체를 압축 백업하기 mysql dir : /var/lib (데이터베이스 디렉토리) [root@byungun lib]# tar cvfpz mysql_dir_tar.gz /var/lib/mysql - 특정 데이터베이스 백업과 복구 백업 형식 : mysqldump -u DB계정명 -p DB명 > 저장할파일명 복구 형식 : mysql -u DB계정명 -p DB명 < 저장할파일명 # mysql DB 백업 [root@byungun DB_backup]# mysqldump -u root -p mysql > mysqldb.sql Enter password: [root@byungun DB_backup]# ls mysqldb.sql # mysql DB 테이블 확인 [root@byungun DB_backup]# mysqlshow -u root -p mysql Enter password: Database: mysql +---------------------------+ | Tables | +---------------------------+ | columns_priv | | db | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | proc | | procs_priv | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ # mysql DB 삭제 [root@byungun DB_backup]# mysqladmin -u root -p drop mysql Enter password: Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'mysql' database [y/N] y Database "mysql" dropped # mysql DB 생성 [root@byungun DB_backup]# mysqladmin -u root -p create mysql Enter password: # mysql DB 복구 [root@byungun DB_backup]# mysql -u root -p mysql < mysqldb.sql Enter password: - 특정 데이터베이스의 특정 테이블 백업과 복구 백업 형식 : mysqldump -u DB계정명 -p DB명 Table명 > 저장할파일명 복구 형식 : mysql -u DB계정명 -p DB명 < 저장할파일명 # mysql DB Table 백업 [root@byungun DB_backup]# mysqldump -u root -p testdb testtable > testtable_table.sql Enter password: [root@byungun DB_backup]# ls -l -rw-r--r-- 1 root root 2017 11월 4 19:09 testtable_table.sql # mysql DB Table 복구 [root@byungun DB_backup]# mysql -u root -p testdb < testtable_table.sql Enter password: - 여러 개의 데이터베이스 한 번에 백업과 복구 백업 형식 : mysqldump -u DB계정명 -p --databases [옵션] DB1 DB2 DB3 > 저장할파일명 복구 형식 : mysql -u DB계정명 -p < 저장할파일명 # mysql 여러 개의 DB 백업 [root@byungun DB_backup]# mysqldump -u root -p --databases tempdb testdb > various_db.sql Enter password: # mysql tempdb tempdb DB 삭제 [root@byungun DB_backup]# mysqladmin -u root -p drop tempdb Enter password: Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'tempdb' database [y/N] y Database "tempdb" dropped [root@byungun DB_backup]# mysqladmin -u root -p drop testdb Enter password: Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'testdb' database [y/N] y Database "testdb" dropped # mysql DB 복구 [root@byungun DB_backup]# mysql -u root -p < various_db.sql Enter password: # mysql tempdb, testdb DB 확인 [root@byungun DB_backup]# mysqlshow -u root -p tempdb Enter password: Database: tempdb +-----------+ | Tables | +-----------+ | temptable | +-----------+ [root@byungun DB_backup]# mysqlshow -u root -p testdb Enter password: Database: testdb +-----------+ | Tables | +-----------+ | testtable | +-----------+ [root@byungun DB_backup]# - MySQL 전체 데이터베이스 백업과 복구 백업 형식 : mysqldump -u DB계정명 -p --all-databases > 저장할파일명 복구 형식 : mysql -u DB계정명 -p < 저장할파일명
댓글목록
등록된 댓글이 없습니다.