MySQL数据库备份与恢复-实验

一、实验目的

掌握数据库备份与恢复的方法。

二、实验内容

使用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.

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

moon-Joe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值