mysqldump 備份單張表和恢復
1、使用工具mysqldump
步驟一:備份表
命令:mysqldump -uroot -p1qazxsw2 -S /var/lib/mysql/mysql.sock --tab=/soft/ huzhicheng user ----huzhicheng為資料庫名稱,user 為我們備份的表名稱
在/soft 目錄下會有兩個檔案,一個字尾為.sql 一個為.txt .sql 為表結構.txt 儲存的是資料
步驟二:恢復表使用命令先恢復表結構
這裡我恢復到test庫裡面做測試,使用mysql 命令建立表使用的檔案就是我們剛才備份的.sql 檔案 命令列如下:
mysql -uroot -p1qazxsw2 -S /var/lib/mysql/mysql.sock test 完成後去test庫檢視錶是否建立
[root@mysql mysql]# mysql -uroot -p1qazxsw2
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.6.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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 test
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> desc user;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(10) | NO | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| addr | varchar(50) | YES | | NULL | |
| phone | varchar(12) | YES | | NULL | |
| age | varchar(3) | YES | | NULL | |
| id | varchar(10) | NO | PRI | | |
| id2 | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
8 rows in set (0.00 sec)
步驟一:備份表
命令:mysqldump -uroot -p1qazxsw2 -S /var/lib/mysql/mysql.sock --tab=/soft/ huzhicheng user ----huzhicheng為資料庫名稱,user 為我們備份的表名稱
在/soft 目錄下會有兩個檔案,一個字尾為.sql 一個為.txt .sql 為表結構.txt 儲存的是資料
步驟二:恢復表使用命令先恢復表結構
這裡我恢復到test庫裡面做測試,使用mysql 命令建立表使用的檔案就是我們剛才備份的.sql 檔案 命令列如下:
mysql -uroot -p1qazxsw2 -S /var/lib/mysql/mysql.sock test 完成後去test庫檢視錶是否建立
[root@mysql mysql]# mysql -uroot -p1qazxsw2
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.6.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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 test
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> desc user;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(10) | NO | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| addr | varchar(50) | YES | | NULL | |
| phone | varchar(12) | YES | | NULL | |
| age | varchar(3) | YES | | NULL | |
| id | varchar(10) | NO | PRI | | |
| id2 | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
8 rows in set (0.00 sec)
表已經存在
下面恢復資料
登入資料庫:
[root@mysql mysql]# mysql -uroot -p1qazxsw2
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.6.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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 test
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>load data infile '/soft/user.txt' into table user;
這樣就完成了資料的恢復。
下面恢復資料
登入資料庫:
[root@mysql mysql]# mysql -uroot -p1qazxsw2
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.6.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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 test
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>load data infile '/soft/user.txt' into table user;
這樣就完成了資料的恢復。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26764973/viewspace-1460511/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【mysqldump】mysqldump及備份恢復示例MySql
- mysqldump常用備份恢復方法MySql
- mysql備份恢復mysqldump面面觀MySql
- 使用Mysqldump備份和恢復MySQL資料庫MySql資料庫
- 使用mysqldump對mysql進行備份和恢復MySql
- windwos server 路由備份和恢復 路由表備份和恢復Server路由
- mysql之 mysqldump 備份恢復詳解MySql
- mysqldump 備份匯出資料排除某張表或多張表MySql
- 從MySQL全庫備份中恢復某個庫和某張表MySql
- 備份和恢復
- 【物理熱備】(下)備份恢復系統表空間 手工備份恢復
- redis 備份和恢復Redis
- 備份和恢復redisRedis
- Mysql備份和恢復MySql
- Oracle 備份和恢復Oracle
- 從全備份的SQL語句中恢復某張表 [原創]SQL
- 利用MySQL全備份(mysqldump),如何只恢復一個庫或者一個表?MySql
- MySQL備份和恢復資料表的方法MySql
- Backup And Recovery User's Guide-備份和恢復概覽-備份和恢復介紹-備份和恢復的目的GUIIDE
- 如何從MySQL全庫備份的dump檔案中恢復某張表和表結構MySql
- SqlServer備份和恢復(二)SQLServer
- SqlServer 備份和恢復(一)SQLServer
- 【MySQL】MySQL備份和恢復MySql
- MySQL 備份和恢復 一MySql
- oracle冷備份、恢復和異機恢復Oracle
- 【備份恢復】從備份恢復資料庫資料庫
- 【管理篇備份恢復】備份恢復基礎
- mysqldump使用方法(MySQL資料庫的備份與恢復)MySql資料庫
- Oracle備份恢復之熱備份恢復及異機恢復Oracle
- linux的OS簡單的備份和恢復Linux
- 簡單的mysqldump備份(windows)MySqlWindows
- ORACLE備份和恢復 - 邏輯備份 exp/impOracle
- 簡單恢復模式下的備份模式
- 單例項備份恢復成RAC單例
- Oracle 備份和恢復介紹Oracle
- redis備份和恢復的方式Redis
- 【MySql】innobackupex增量備份和恢復MySql
- 【MySql】innobackupex 增量備份和恢復MySql