数据备份和还原

-- 单表数据备份

select *  into outfile 'C:/Users/78/Desktop/web/web2/web/student.txt' from my_student;

select *  into outfile 'C:/Users/78/Desktop/web/web2/web/class.txt' from my_class;

-- 指定备份处理方式

select * into outfile 'C:/Users/78/Desktop/web/web2/web/class1.txt'

fields

enclosed by '"' -- 数据使用双引号包裹

terminated by '|' -- 使用竖线分隔字段数据

-- 行处理

lines

starting by 'select:'

from my_class;

-- 还原数据

load data infile 'C:/Users/78/Desktop/web/web2/web/class1.txt' into table my_classfields enclosed by '"' terminated by

'|' lines starting by 'START';

select * from my_class;

-- sql备份

mysqldump -uroot -proot mybd my_student > C:/Users/78/Desktop/web/web2/web/student.sql

-- 整库备份

mysqldump -uroot -proot mybd > C:/Users/78/Desktop/web/web2/web/mybd.sql

-- sql 还原

drop table my_student;

show tables ;

\q

-- 还原数据:mysql客户端还原

mysql -uroot -proot mybd < C:/Users/78/Desktop/web/web2/web/mybd.sql;

select * from my_student;

drop table my_student; -- 删除学生表

-- sql指令还原sql备份

source C:/Users/78/Desktop/web/web2/web/mybd.sql;

select  * from my_student;

你可能感兴趣的:(数据备份和还原)