Home > Database > Mysql Tutorial > body text

What should I do if mysql data is accidentally deleted?

coldplay.xixi
Release: 2020-10-29 16:22:05
Original
2380 people have browsed it

mysql数据意外删除的解决办法:首先在数据库文件存放的data目录里找到【mysql-bin.00000x】文件;然后导出成txt格式;最后输入相关语句进行恢复数据。

What should I do if mysql data is accidentally deleted?

mysql数据意外删除的解决办法:

1、先确认mysql有没有启用bin日志 ,就是看下mysql.ini(my.cnf)里的log-bin=mysql-bin, 可以 自定义一个目录和前缀名,比如/data/log/mylog这样。

2、然后在数据库文件存放的data目录就能看到mysql-bin.00000x这样的文件,这就是二进制日志了,可以导出成txt格式的,里面其实就是对数据库的各种操作sql语句。

3、导出txt文件:

e:\wamp\bin\mysql\mysql5.6.12\bin>mysqlbinlog
--database=testdatabase
e:\wamp\bin\mysql\mysql5.6.12\data\mysql-bin.000312
>
c:\\test1.txt
Copy after login

这是windows下的导出,linux也是类似的。

database=数据库名

从最早的日志还始还原

linux下可以很方便的 mysql-bin.000*

可以加参数开始时间和结束时间,就是你执行那条sql语句的时间

start-datetime="2014-12-04
11:25:56"
--stop-datetime="2014-12-04
13:23:50"
Copy after login

4、恢复数据:

e:\wamp\bin\mysql\mysql5.6.12\bin>mysqlbinlog
--database=yundongchao
e:\wamp\bin\mysql\mysql5.6.12\data\mysql-bin.000179
|
mysql
-u
root
-p
Copy after login

更多相关免费学习推荐:mysql教程(视频)

The above is the detailed content of What should I do if mysql data is accidentally deleted?. For more information, please follow other related articles on the PHP Chinese website!

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!