mysql数据库备份方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lihua5419/article/details/81938566

一、备份

1、使用SQLyog可视化工具备份,SQLyog工具可参考https://blog.csdn.net/lihua5419/article/details/73881837

右键需要备份的数据库-备份/导出-备份数据库

2、总有一些人不习惯使用可视化工具,可用命令行模式进行备份,打开cmd命令行窗口

(1)输入命令:mysqldump -u root -p 数据库名称>文件位置:\ 数据库名.sql

然后输入数据库root密码即可

(2)如果只想备份出student库下的teacher表,

mysqldump -u root -p student teacher > E:\student_teacher.sql

(3)备份所有数据库

mysqldump -u -root -p -all-databases > E:\all.sql

3、linux系统下备份

(1)cd进入mysql目录

[root@localhost ]# cd /xxx/zzz/mysql

(2)在当前目录/xxx/zzz/mysql 生成名为student.sql的文件,如果想备份在其他位置,再生成的文件名前加上文件存放路径即可

[root@localhost ]# mysqldump -u root -p student > student.sql

二、还原

1、SQLyog右键数据库,导入->导入sql脚本,选择备份的sql文件即可

2、命令行模式导入命令:mysql -u root -p 数据库名< E:\student.sql

3、Linux下还原数据库

(1)cd进入mysql目录

[root@localhost ~]# cd /xxx/zzz/mysql

(2)导入执行sql文件

[root@localhost mysql]# mysql -u root -p student < student.sql

猜你喜欢

转载自blog.csdn.net/lihua5419/article/details/81938566
今日推荐