mysql数据库为了数据的平安,供给了备份恢复的方式,我和大师分享一下备份恢复过程,我写的经验对你进修mysql有帮忙的话,给我投票、点赞或者保藏!
登录mysql,在test数据库新建一个表chengshi:
Create Table
CREATE TABLE `chengshi` ( `id` int(11) NOT NULL AUTO_INCREMENT, `shengfen` varchar(10) DEFAULT NULL, `chengshi` varchar(10) DEFAULT NULL, `shijian` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8
在表中输入数据:
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('1','河南','安阳','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('2','河南','郑州','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('3','河南','洛阳','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('4','河南','漯河','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('5','河南','新乡','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('6','河南','濮阳','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('7','河南','焦作','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('8','河南','鹤壁','2019-03-05 10:14:27');
insert into `chengshi` (`id`, `shengfen`, `chengshi`, `shijian`) values('9','河南','开封','2019-03-05 10:14:27');
把表的数据备份c:\chengshi.sql文件中:
SELECT * INTO OUTFILE 'c:/chengshi.sql' FROM chengshi
这个文件备份的表的数据,把备份的数据恢复的 表中。
备份的本家儿键和表的本家儿键反复,所有替代数据:
LOAD DATA INFILE 'c:/chengshi.sql' REPLACE INTO TABLE chengshi
备份的本家儿键和表的本家儿键反复,把没有的数据恢复到表中:
DELETE FROM chengshi WHERE id>=3;
LOAD DATA INFILE 'c:/chengshi.sql' IGNORE INTO TABLE chengshi;
查询所稀有据:
SELECT * FROM chengshi;
0 篇文章
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!