mysql 数据库备份和还原 实践
1、备份mysql数据库中的数据库mysql
备份test数据库中的单张表:
C:\Documents and Settings\Administrator>mysqldump -uroot -p test t2>d:/t2bak.txt
Enter password:
备份test数据中的t2,t1两张表:
C:\Documents and Settings\Administrator>mysqldump -uroot -p test t2 t1>d:/t2bak.txt
Enter password:
注意:在备份一个数据库中的两张表的时候用空格隔开,不能用"," 号,并且要求是英文状态下的符号。
2、有路径的文件导出具体做法
3、上面的目录可以是你想将数据库备份放置的位置(f:/mysql1.sql)
4、如果不带数据库的备份路径时数据库存储的位置是当前目录下
1、删除表t2:
mysql> drop table t2;
Query OK, 0 rows affected (0.02 sec)
2、已经不存在了:
mysql> select * from t2
ERROR 1146 (42S02): Table 'test.t2' doesn't exist
3、还原:
C:\Documents and Settings\Administrator>mysql test <d:/t2bak.txt
OR
mysql> source d:/t2bak.txt
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.03 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 5 rows affected (0.00 sec)
Records: 5
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.05 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
4、查询已恢复:
mysql> select * from t2
+---+
| a |
+---+
| 1 |
| 2 |
| 3 |
| 4 |
| 6 |
+---+
5 rows in set (0.00 sec)
本文出自 “守候者” 博客,请务必保留此出处http://shouhouzhe.blog.51cto.com/2351955/1376942
更多相关文章
- python数据存储系列教程——python中mysql数据库操作:连接、增删
- MongoDB备份恢复与导入导出
- mysql数据库的主从同步过程详述
- 直接的文件备份和用sqlserver的备份有什么区别
- 工作日记(连接SQL Sever 2005服务器数据库)
- docker应用-6(mysql+mycat 搭建数据库集群)
- mysql数据库基本操作指南
- 项目连接MySQL数据库,提示异常
- MySQL数据库SQL语法