Home Database Mysql Tutorial 记一次mysql数据库binlog丢失引起的故障

记一次mysql数据库binlog丢失引起的故障

Jun 07, 2016 pm 05:38 PM
insert java program sql statement app

线上某业务需要对日志信息入库并进行分析最后呈现在管理后台上。某天突然发现后台没有前一天的分析数据。首先认为是java程序问题,于是查看应用程序日志,发现数

线上某业务需要对日志信息入库并进行分析最后呈现在管理后台上。某天突然发现后台没有前一天的分析数据。首先认为是java程序问题,于是查看应用程序日志,发现数据缺失的那天应用程序日志也没有记录,很是奇怪。接着手动执行jar包,本想看屏幕输出的报错信息,结果程序刚启动运行,执行了3条入库的sql语句(insert)后便卡住不动了,反复尝试了2-3次都是这种情况,接着怀疑是远程的mysql数据库问题导致无法插入新数据。

连接到远程数据库上,首先查看磁盘的分区df-h,果然mysql所在的数据库分区(/data)磁盘空间使用率居然达到了100%,太吓人了。果断du-sch*/data定位到具体的目录下的大文件,发现均为mysql的binlog文件

233930722.jpg

每个文件均为1.1G,这是mysql数据库binlog的默认值

234328632.jpg

查看mysql错误日志,如下信息:

131019 3:00:12 [ERROR] /usr/local/mysql/bin/mysqld: Disk is full writing './mysql-bin.000261' (Errcode: 28). Waiting for someone to free space... (Expect up to 60 secs delay for server to continue after freeing disk space) 131019 3:00:12 [ERROR] /usr/local/mysql/bin/mysqld: Retry in 60 secs. Message reprinted in 600 secs 131019 3:10:12 [ERROR] /usr/local/mysql/bin/mysqld: Retry in 60 secs. Message reprinted in 600 secs

基本可以断定是应用程序在insert新的数据时,由于磁盘空间不足导致无法写入binlog文件导致无法插入新数据。

情急之下先删除了部分binlog,后设置max_binlog_size=500M,文件被truncate了,然后重启mysql数据库,悲剧的事情发生了,数据无法正常启动,再次查看错误日志:

/usr/local/mysql/bin/mysqld: File './mysql-bin.index' not found (Errcode: 13)

有时出现这个错误是文件权限不正确导致,确定了mysql-bin.index文件的权限是没有问题的,属主和属组都是mysql

关闭mysqlbinlog的功能,在/etc/my.cnf中加入log-bin=0,数据库还是无法启动。

最后查看mysql-bin.index文件里的内容,描述的binlog文件都被删除了,问题就在这里。

只有重新初始化数据库,第一次没有指定datadir重启后出错:

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

再次初始化数据库,记得在/etc/my.cnf里把log-bin=0删除或者注释,因为需要开启binlog功能,连同binlog相关参数一起初始化,否则会报错。

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/core

再次重启终于,数据终于起来了,执行应用程序入库也正常了,将之前的测试数据清除,,以免插入重复数据,最后执行应用程序入库。

以上为对一次案例的排错主要过程,期间还有一些小的经过,最终把问题解决。

总结:binlog是可以关闭的,但是很少有人这么做,可以通过showvariableslike'expire_logs_days'查看binlog的过期时间;setglobalexpire_logs_days=10设置binlog的过期时间,但是一般都是会对binlog定期删除,比如7天以上的打tar包,一个月以上的删除tar包等,当然重要的需要单独保留。

本文出自 “老徐的私房菜” 博客,谢绝转载!

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to connect Apple Vision Pro to PC How to connect Apple Vision Pro to PC Apr 08, 2024 pm 09:01 PM

The Apple Vision Pro headset is not natively compatible with computers, so you must configure it to connect to a Windows computer. Since its launch, Apple Vision Pro has been a hit, and with its cutting-edge features and extensive operability, it's easy to see why. Although you can make some adjustments to it to suit your PC, and its functionality depends heavily on AppleOS, so its functionality will be limited. How do I connect AppleVisionPro to my computer? 1. Verify system requirements You need the latest version of Windows 11 (Custom PCs and Surface devices are not supported) Support 64-bit 2GHZ or faster fast processor High-performance GPU, most

How to use the iif function in excel How to use the iif function in excel Mar 20, 2024 pm 06:10 PM

Most users use Excel to process table data. In fact, Excel also has a VBA program. Apart from experts, not many users have used this function. The iif function is often used when writing in VBA. It is actually the same as if The functions of the functions are similar. Let me introduce to you the usage of the iif function. There are iif functions in SQL statements and VBA code in Excel. The iif function is similar to the IF function in the excel worksheet. It performs true and false value judgment and returns different results based on the logically calculated true and false values. IF function usage is (condition, yes, no). IF statement and IIF function in VBA. The former IF statement is a control statement that can execute different statements according to conditions. The latter

Shazam app not working in iPhone: Fix Shazam app not working in iPhone: Fix Jun 08, 2024 pm 12:36 PM

Having issues with the Shazam app on iPhone? Shazam helps you find songs by listening to them. However, if Shazam isn't working properly or doesn't recognize the song, you'll have to troubleshoot it manually. Repairing the Shazam app won't take long. So, without wasting any more time, follow the steps below to resolve issues with Shazam app. Fix 1 – Disable Bold Text Feature Bold text on iPhone may be the reason why Shazam is not working properly. Step 1 – You can only do this from your iPhone settings. So, open it. Step 2 – Next, open the “Display & Brightness” settings there. Step 3 – If you find that “Bold Text” is enabled

How to query oracle database logs How to query oracle database logs Apr 07, 2024 pm 04:51 PM

Oracle database log information can be queried by the following methods: Use SQL statements to query from the v$log view; use the LogMiner tool to analyze log files; use the ALTER SYSTEM command to view the status of the current log file; use the TRACE command to view information about specific events; use operations System tools look at the end of the log file.

How to Install and Run the Ubuntu Notes App on Ubuntu 24.04 How to Install and Run the Ubuntu Notes App on Ubuntu 24.04 Mar 22, 2024 pm 04:40 PM

While studying in high school, some students take very clear and accurate notes, taking more notes than others in the same class. For some, note-taking is a hobby, while for others, it is a necessity when they easily forget small information about anything important. Microsoft's NTFS application is particularly useful for students who wish to save important notes beyond regular lectures. In this article, we will describe the installation of Ubuntu applications on Ubuntu24. Updating the Ubuntu System Before installing the Ubuntu installer, on Ubuntu24 we need to ensure that the newly configured system has been updated. We can use the most famous "a" in Ubuntu system

How to use sql statement to query the storage structure of mysql database How to use sql statement to query the storage structure of mysql database Apr 14, 2024 pm 07:45 PM

To query the MySQL database storage structure, you can use the following SQL statement: SHOW CREATE TABLE table_name; this statement will return the column definition and table option information of the table, including column name, data type, constraints and general properties of the table, such as storage engine and character set.

How to export the queried data in navicat How to export the queried data in navicat Apr 24, 2024 am 04:15 AM

Export query results in Navicat: Execute query. Right-click the query results and select Export Data. Select the export format as needed: CSV: Field separator is comma. Excel: Includes table headers, using Excel format. SQL script: Contains SQL statements used to recreate query results. Select export options (such as encoding, line breaks). Select the export location and file name. Click "Export" to start the export.

How to execute sql statement in mysql database How to execute sql statement in mysql database Apr 14, 2024 pm 07:48 PM

MySQL SQL statements can be executed by: Using the MySQL CLI (Command Line Interface): Log in to the database and enter the SQL statement. Using MySQL Workbench: Start the application, connect to the database, and execute statements. Use a programming language: import the MySQL connection library, create a database connection, and execute statements. Use other tools such as DB Browser for SQLite: download and install the application, open the database file, and execute the statements.

See all articles