Home > Database > Mysql Tutorial > body text

Mysql自动备份与还原_MySQL

WBOY
Release: 2016-06-01 13:52:12
Original
955 people have browsed it

一、自动备份:将以下代码保存为*.bat批处理脚本,然后再添加Windows定时作业,如每天凌晨2点执行:
set s=%date:~0,4%%date:~5,2%%date:~8,2%%time:~1,1%%time:~3,2%%time:~6,2%
mysqldump -u root -ppassword databasename > d:/databasename_%s%_bak.sql

说明:databasename 为数据库名 password为数据库密码,系统自动以当前日期时间备份至指定目录。

a.只导出表结构:mysqldump -uroot -–no-data test > test.txt

b.只导出a表的数据: mysqldump -uroot -–no-create-info test a> test.txt

【注意】:用mysqldump,如果不加任何参数,dump出来的文件,如果存在表则会先drop table,然后再create table
,最后insert数据。所以要特别注意。可以通过添加参数去掉drop或者直接去掉create,如mysqldump –no-create-info
、mysqldump –add-drop-table=’false’ ,当然最安全最正确的做法是导入之前先检查文件,是否存在drop等命令会破坏原有表。

二、还原数据库: mysql -u root -p databasename

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!