一、实验项目:
数据库备份与恢复。
二、实验目的
1、会使用SQL语句备份和恢复数据库。
2、会使用SQL语句导入和导出表中的数据。
三、实验内容
使用SQL语句完成下列题目:
1、使用mysqldump命令备份数据库agristore中的所有表,将其备份到D:\,备份文件名为agristore_backup.sql。
2、使用mysql命令将备份文件agristore_backup.sql恢复到数据库agristore中。
3、使用source命令将备份文件agristore_backup.sql恢复到数据库agristore中。
4、使用mysqldump命令备份数据库agristore中的orders表,将其备份到D:\,备份文件名为agristore_orders.sql。
5、删除orders表的数据,用source命令恢复。
6、使用mysqldump命令备份数据库agristore的结构到d盘之下,备份名称为agristore_structure.sql。
7、将agristore数据库product表中的数据导出到D盘file目录中,要求字段值用双引号标注,字段值之间用逗号隔开,每行以回车换行为结束标志。
8、删除product表中的数据,然后将导出后的数据导入到product表中。
四、实验参考代码及执行结果截图
1、mysqldump -u root -p agristore > d:/agristore_backup.sql
2、mysql -u root -p agristore < d:/agristore_backup.sql
恢复前:
Drop table account;
Show tables;
恢复后:Show tables;
3、source d:/agristore_backup.sql;
恢复前:
Drop table account;
Show tables;
恢复后:Show tables;
4、mysqldump -u root -p agristore orders> d:/agristore_orders.sql
5、Delete from orders;
source d:/agristore_orders.sql;
恢复前:select * from orders;
恢复后:select * from orders;
6、mysqldump -u root -p --opt --no-data agristore>d:/agristore_structure.sql
7、select * from product into outfile 'd:/file/ product.txt'
fields terminated by ','
enclosed by '"'
lines terminated by '\r\n';
8、delete from product;
load data infile 'D:/file/ product.txt'
into table product
fields terminated by ','
enclosed by '"'
lines terminated by '\r\n';
恢复前:select * from product;
恢复后:select * from product;