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資料庫
- innobackupex 部分表備份和恢復
- mysqldump 備份匯出資料排除某張表或多張表MySql
- 使用Xtrabackup完整備份中恢復單表
- 備份和恢復
- 利用MySQL全備份(mysqldump),如何只恢復一個庫或者一個表?MySql
- KunlunDB備份和恢復
- redis 備份和恢復Redis
- mysqldump使用方法(MySQL資料庫的備份與恢復)MySql資料庫
- SqlServer備份和恢復(二)SQLServer
- SqlServer 備份和恢復(一)SQLServer
- 【MySQL】MySQL備份和恢復MySql
- RAC備份恢復之Voting備份與恢復
- 簡單的mysqldump備份(windows)MySqlWindows
- mysqldump 恢復單個資料庫MySql資料庫
- Oracle 備份和恢復介紹Oracle
- 備份與恢復:polardb資料庫備份與恢復資料庫
- MySQL備份與恢復——基於Xtrabackup物理備份恢復MySql
- SYSTEM 表空間管理及備份恢復
- mydumper備份恢復
- Mysql備份恢復MySql
- 九 GBase 8a備份和恢復
- gitlab的資料備份和恢復Gitlab
- MySQL日誌管理,備份和恢復MySql
- MySQL備份和恢復方法彙總MySql
- 詳解叢集級備份恢復:物理細粒度備份恢復
- MySQL備份與恢復——基於MyDumper/MyLoader 邏輯備份恢復MySql
- 從nub備份恢復(同平臺)恢復RAC至單例項單例
- Mysql備份與恢復(1)---物理備份MySql
- rman 增量備份恢復
- Jenkins備份與恢復Jenkins
- Postgresql 備份與恢復SQL
- MySQL 備份與恢復MySql
- RMAN備份恢復技巧
- Grafana 備份恢復教程Grafana
- 帝國cms備份和恢復 帝國cms恢復資料
- Mongo 資料庫備份和恢復命令Go資料庫
- DBV:冷備份的校驗和恢復