实验6 数据库备份与恢复

一、实验项目:

数据库备份与恢复。

实验目的

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值