search
HomeDatabaseMysql TutorialMySQL数据库Drop Down后的紧急处置_MySQL

前言

今天下午3点,我按照惯例,打开游戏服务器,开新服部署嘛,游戏在腾讯开放平台,简单。闭着眼睛都OK。于是一轮子的复制黏贴拷贝,把服务器加起来,然后启动查看日志。

。。。。突然发现不断的有Exception?搞什么?丢失表Usr_user??刚才不是导了数据库吗?不存在?怎么会?

我瞬间意识到。我摊上事了,我摊上大事了。。检查刚才的复制黏贴,发现我没改数据库名,这一下子把第二个服的数据库整个干掉了。

我擦!!不会吧??背后一凉就软滩在凳子上了。

备份?没有。

数据库还有渣吗?select count(*) ....  0!

备份?真的没有。

怎么能没备份啊!

怎么办?几十个玩家充值了几千元。连个影子也没了。

找玩家求饶?送礼包?? 你觉得玩家会放过你?天真。

linux服务器 + mysql数据库 + 游戏缓存 + flash的as3前端。怎么搞。。。我完蛋了。

HOLD住!

我要HOLD住!冷静,虽然大脑一片空白。马上Google找mysql有无自动备份的。。。没看到。问同事,求助。我靠,他们怎么好像没反应啊。。。

这个时候,有个哥们提示我,用 mysqlbinlog。

这玩意是什么。马上google,知道mysql自身会有个操作的备份。我靠!希望来了。赶快进入mysql目录,查看下。果然看到几十个bin文件。

网上继续搜。大概知道mysql会保存30天内的数据库操作在bin文件。OK。

 

我们达洛克2服才刚运行了2天,算起来应该就是最后2个bin文件。还好。用

 

<ol class="dp-sql"><li class="alt"><span><span>mysqlbinlog </span><span class="comment">--no-defaults mysql-bin.000026 > mysql-bin.000026.txt</span><span> </span></span></li></ol>

导出了SQL,检查下:

<ol class="dp-sql">
<li class="alt"><span><span># </span><span class="keyword">at</span><span> 472331597 </span></span></li>
<li><span>#130619 18:04:23 server id 1  end_log_pos 472331772     Query   thread_id=2657  exec_time=0     error_code=0 </span></li>
<li class="alt"><span><span class="keyword">SET</span><span> </span><span class="keyword">TIMESTAMP</span><span>=1371636263/*!*/; </span></span></li>
<li><span><span class="keyword">UPDATE</span><span> USR_RESOURCE </span><span class="keyword">SET</span><span> MODIDATE = </span><span class="string">'2013-06-19 18:04:23'</span><span>,SILVER = 283 </span><span class="keyword">WHERE</span><span> USERCODE=</span><span class="string">'001UR1371634524003511'</span><span> </span></span></li>
<li class="alt"><span>/*!*/; </span></li>
<li><span># <span class="keyword">at</span><span> 472331772 </span></span></li>
<li class="alt"><span>#130619 18:04:23 server id 1  end_log_pos 472331799     Xid = 226001034 </span></li>
<li><span><span class="keyword">COMMIT</span><span>/*!*/; </span></span></li>
<li class="alt"><span># <span class="keyword">at</span><span> 472331799 </span></span></li>
<li><span>#130619 18:04:23 server id 1  end_log_pos 472331871     Query   thread_id=2657  exec_time=0     error_code=0 </span></li>
<li class="alt"><span><span class="keyword">SET</span><span> </span><span class="keyword">TIMESTAMP</span><span>=1371636263/*!*/; </span></span></li>
<li><span><span class="keyword">BEGIN</span><span> </span></span></li>
</ol>

大概是这种结构。

冷静下来,分析了。我还原数据库,只要从建库开始第一个sql重新执行到最后一个。理论上数据库就会被还原。但是bin文件里面是所有的SQL操作,我要筛选出 达洛克战记2服 的。网上说用 cat / more / less 等命令。我靠,这他妈也太复杂了把?

于是我zip了所有bin文件,回传到本地,用c#写了个过滤代码,找到 use darok2_2,知道这段内容都是 达洛克战记2服 的数据。

<ol class="dp-c">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> test() </span></span></li>
<li><span>{ </span></li>
<li class="alt"><span>    FileStream stream = File.OpenRead(@<span class="string">"E:\玩转中国\程序设计\达洛克战记\xtar-backup\svn\达洛克战记2x\svn\server-deploy\mysql-bin.000027.txt\mysql-bin.000027.txt"</span><span>); </span></span></li>
<li><span>    StreamReader reader = <span class="keyword">new</span><span> StreamReader(stream, Encoding.GetEncoding(</span><span class="string">"GBK"</span><span>)); </span></span></li>
<li class="alt"><span> </span></li>
<li><span>    FileStream streamO = File.Create(@<span class="string">"E:\玩转中国\程序设计\达洛克战记\xtar-backup\svn\达洛克战记2x\svn\server-deploy\mysql-bin.000027.txt\000027.out.txt"</span><span>); </span></span></li>
<li class="alt"><span>    StreamWriter writer = <span class="keyword">new</span><span> StreamWriter(streamO, Encoding.GetEncoding(</span><span class="string">"GBK"</span><span>)); </span></span></li>
<li><span> </span></li>
<li class="alt"><span>    Encoding gbk = Encoding.GetEncoding(<span class="string">"GBK"</span><span>); </span></span></li>
<li><span>    Encoding utf = Encoding.Default; </span></li>
<li class="alt"><span> </span></li>
<li><span>    <span class="keyword">string</span><span> strLine = reader.ReadLine(); </span></span></li>
<li class="alt"><span> </span></li>
<li><span>    <span class="keyword">while</span><span> (strLine != </span><span class="keyword">null</span><span>) </span></span></li>
<li class="alt"><span>    { </span></li>
<li><span> </span></li>
<li class="alt"><span>        <span class="keyword">if</span><span> (!strLine.StartsWith(</span><span class="string">"use darok2_2"</span><span>, StringComparison.OrdinalIgnoreCase)) </span></span></li>
<li><span>        { </span></li>
<li class="alt"><span>            strLine = reader.ReadLine(); </span></li>
<li><span>            <span class="keyword">continue</span><span>; </span></span></li>
<li class="alt"><span>        } </span></li>
<li><span> </span></li>
<li class="alt"><span>        <span class="keyword">do</span><span> </span></span></li>
<li><span>        { </span></li>
<li class="alt"><span>            <span class="keyword">if</span><span> (strLine == </span><span class="keyword">null</span><span>) </span></span></li>
<li><span>                <span class="keyword">break</span><span>; </span></span></li>
<li class="alt"><span> </span></li>
<li><span>            <span class="keyword">if</span><span> (strLine.StartsWith(</span><span class="string">"use"</span><span>, StringComparison.OrdinalIgnoreCase) && !strLine.StartsWith(</span><span class="string">"use darok2_2"</span><span>, StringComparison.OrdinalIgnoreCase)) </span></span></li>
<li class="alt"><span>            { </span></li>
<li><span>                strLine = reader.ReadLine(); </span></li>
<li class="alt"><span>                <span class="keyword">break</span><span>; </span></span></li>
<li><span>            } </span></li>
<li class="alt"><span> </span></li>
<li><span>            <span class="keyword">if</span><span> (strLine.StartsWith(</span><span class="string">"INSERT"</span><span>, StringComparison.OrdinalIgnoreCase) || strLine.StartsWith(</span><span class="string">"DELETE"</span><span>, StringComparison.OrdinalIgnoreCase) || strLine.StartsWith(</span><span class="string">"UPDATE"</span><span>, StringComparison.OrdinalIgnoreCase)) </span></span></li>
<li class="alt"><span>            { </span></li>
<li><span>                writer.Write(strLine); </span></li>
<li class="alt"><span>                writer.WriteLine(<span class="string">";"</span><span>); </span></span></li>
<li><span>            } </span></li>
<li class="alt"><span>            <span class="keyword">else</span><span> </span></span></li>
<li><span>            { </span></li>
<li class="alt"><span>            } </span></li>
<li><span>            strLine = reader.ReadLine(); </span></li>
<li class="alt"><span> </span></li>
<li><span>        } </span></li>
<li class="alt"><span>        <span class="keyword">while</span><span> (</span><span class="keyword">true</span><span>); </span></span></li>
<li><span>    } </span></li>
<li class="alt"><span> </span></li>
<li><span>    writer.Flush(); </span></li>
<li class="alt"><span>    writer.Close(); </span></li>
<li><span> </span></li>
<li class="alt"><span>    reader.Close(); </span></li>
<li><span>} </span></li>
</ol>

这样,我就得到过滤出来的SQL文件了。本地我建了个数据库测试下,发现第一句就卡死了??HOLD住!!!

再细心看看,发现中文到了txt全部是乱码了。安静思考了下:

linux数据库用的是GBK。因此bin文件导出的格式一定是GBK。那么代码用GBK读取,然后GBK写入就ok了(代码里面已经修复了)

再导入,顺利了。

进入数据库在看,发现中文还是乱码。。。。奇怪。那可能是mysql设置的问题了,和linux环境下不一致。我只要把这些过滤的SQL在达洛克服务器上走一遍应该就ok了。

上传SQL,运行脚本:

<ol class="dp-sql"><li class="alt"><span><span>mysql -uxxxx -pxxxx darok2_2 <span class="keyword">out</span><span>.txt. </span></span></span></li></ol>

等了10分钟。。。进入腾讯朋友网,开启游戏。一切又光明了。

总结:

各位看官,别看我洋洋洒洒几句废话貌似几分钟的事情。在那个接近崩溃,连数据库渣都没的条件下。我是多么惨的度过了2个小时。

mysqlbinlog

各位真心要记在心里。如果有全量备份+这个增量备份,基本上数据是不会丢失的。嗨。真实虚惊一场啊。

原文链接:http://www.cnblogs.com/zc22/p/3145080.html

Statement
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!