概念:1)计算机硬件故障 2)计算机软件故障 3)病毒 4)认为误操作 5)自然灾害 6)盗窃
数据备份是指通过导出数据或者复制表文件的方式来制作数据库的复本;
数据库恢复则是当数据库出现故障或遭到破坏时,将备份的数据库加载到系统,从而使数据库从错误状态恢复到备份时的正确状态.
数据库的恢复是以备份为基础的,它是与备份相对应的系统维护和管理操作.
使用select into...outfile语句备份数据
select * outfile 'file_name' export_options
| into dumpfile'file_name' //导出的备份文件里面所有的数据行都会彼此紧挨着放置
[fields
[terminated by 'string']
[[optionally]enclosed by 'char']
[escaped by 'char']
]
[lines tereminated by 'string']
使用load data...infile语句恢复数据
load data infile'file_name.txt'
into table tb_name
[fields
[terminated by 'string']
[[optionally]enclosed by 'char']
[escaped by 'char']
]
[lines
[starting by 'string']
[tereminated by 'string']
]
备份
select * from mysql_test.cust
into outfile 'C:/BACKUP/backupfile.txt'
fields terminated by ',' //字段值用,分开 terminated 终止
optionally enclosed by "" //字符用"标注
lines terminated by '?'; // 以?为结束标志
恢复
load data infile 'C://BACKUP/backupfile.txt'
into table mysql_test.cust_copy
fields terminated by ','
optionally enclosed by ""
lines terminated by '?';