数据库的备份和还原

数据库的备份和还原

技术教程gslnedu2024-12-24 10:29:1413A+A-

通过Mysql命令行形式备份和还原数据库

1、window 系统下的备份和还原

备份
(1)通过cmd命令进入mysql的bin目录下 C:\Program Files\MySQL\MySQL Server 5.5\bin

(2) 输入命令 mysqldump -u root -p test>test.sql

root (用户名) test(数据库名) test.sql(导出文件名)

备份到指定路径,路径中包含空格,需要用双引号包围,

例如备份到桌面 C:\Documents and Settings\Administrator\桌面\test.sql

输入命令 mysqldump -u root -p test>"C:\Documents and Settings\Administrator\桌面\test.sql"

还原

(1)打开mysql客户端命令窗口(Mysql Command Line Client),创建要还原的数据库,上一步导出的是test数据库

create database test;

use test;

(2)source test.sql(还原指定路径下sql文件即可)

2、Linux 下的备份和还原

备份

(1)cd /var/lib/mysql (进图到Mysql的安装目录)

(2) mysqldump -u root -p test>test.sql

还原

(1)cd /var/lib/mysql (Mysql的安装目录)

(2)mysql -u root -p test<test.sql

点击这里复制本文地址 以上内容由朽木教程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

朽木教程网 © All Rights Reserved.  蜀ICP备2024111239号-8