一、实验目的
掌握数据库备份与恢复的方法。
二、实验内容
使用SQL语句完成下列题目:
1、使用mysqldump命令备份数据库petstore中的所有表,将其备份到D:\,备份文件名为petstore_backup.sql。(1分)
2、使用mysql命令将备份文件petstore_backup.sql恢复到数据库petstore中。(0.5分)
3、使用source命令将备份文件petstore_backup.sql恢复到数据库petstore中。(0.5分)
4、使用mysqldump命令备份数据库petstore中的orders表,将其备份到D:\,备份文件名为petstore_orders.sql。(0.5分)
5、删除orders表的数据,用source命令恢复。(0.5分)
6、将petstore数据库product表中的数据导出到D盘file目录中,要求字段值用双引号标注,字段值之间用逗号隔开,每行以回车换行为结束标志。(1分)
7、删除product表中的数据,然后将导出后的数据导入到product表中。(1分)
三、实验代码及注释
1.mysqldump -u root -p petstore >D:/petstore_backup.sql
2.
Drop table account;
Show tables;
mysql -u root -p petstore <D:/petstore_backup.sql
Show tables;
3.
Drop table account;
Show tables;
source D:/petstore_backup.sql
Show tables;
4.mysqldump -u root -p petstore orders >D:/petstore_orders.sql
5.
select * from orders;
truncate table orders;
source D:/petstore_backup.sql
select * from orders;
6.
select * from product into outfile 'D:/file/product.txt'
fields terminated by '\,'
optionally enclosed by '\"'
lines terminated by '\r\n';
7.
select * from product;
truncate table product;
load data infile 'D:/file/product.txt' into table product
fields terminated by '\,'
optionally enclosed by '\"'
lines terminated by '\r\n';
select * from product;
四、运行结果截图
6.