【大数据技术】记一次MySQL启动失败,[ERROR] [MY-010958] [Server] I/O error reading the header from the binary log.

本文讲述了MySQL服务器在清理过程中意外删除binlog文件导致启动失败的问题,通过分析日志发现原因并修复,最终提示用户在使用清理工具时要小心处理相关文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写自定义目录标题

01 背景

一直正常使用的MySQL,今天突然启动失败了,如下图所示
在这里插入图片描述
使用命令“sc query mysql ”查看MySQL当前的状态,如下图
在这里插入图片描述

02 分析

  1. MySQL启动失败,同时查看状态是stopped,故用命令手动启动,发现mysql服务无法启动,无法启动,玩鸟,大问题啦
    在这里插入图片描述
  2. 进入MySQL安装目录查看err日志
    在这里插入图片描述
  3. 打开这个文件,用notepad++打开,发现 I/O error reading the header from the binary log. ,仔细会议原来昨天用清理软件对log文件进行了清理,导致无法读取正确的binlog文件,故而启动不了
    在这里插入图片描述
    2024-04-13T02:23:14.892704Z 0 [Warning] [MY-010097] [Se
### 回答1: import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Iterator; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelToMysql { public static void main(String[] args) { String jdbcUrl = "jdbc:mysql://localhost:3306/test_db"; String username = "root"; String password = "password"; String excelFilePath = "data.xlsx"; int batchSize = 20; Connection connection = null; try { long start = System.currentTimeMillis(); FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); Workbook workbook = new XSSFWorkbook(inputStream); Sheet firstSheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = firstSheet.iterator(); connection = DriverManager.getConnection(jdbcUrl, username, password); connection.setAutoCommit(false); String sql = "INSERT INTO users (name, email, country) VALUES (?, ?, ?)"; PreparedStatement statement = connection.prepareStatement(sql); int count = 0; rowIterator.next(); // skip the header row while (rowIterator.hasNext()) { Row nextRow = rowIterator.next(); Iterator<Cell> cellIterator = nextRow.cellIterator(); while (cellIterator.hasNext()) { Cell nextCell = cellIterator.next(); int columnIndex = nextCell.getColumnIndex(); switch (columnIndex) { case 0: String name = nextCell.getStringCellValue(); statement.setString(1, name); break; case 1: String email = nextCell.getStringCellValue(); statement.setString(2, email); break; case 2: String country = nextCell.getStringCellValue(); statement.setString(3, country); break; } } statement.addBatch(); if (count % batchSize == 0) { statement.executeBatch(); } } workbook.close(); // execute the remaining queries statement.executeBatch(); connection.commit(); connection.close(); long end = System.currentTimeMillis(); System.out.printf("Import done in %d ms\n", (end - start)); } catch (IOException ex1) { System.out.println("Error reading file"); ex1.printStackTrace(); } catch (SQLException ex2) { System.out.println("Database error"); ex2.printStackTrace(); } } } ### 回答2: import java.io.File; import java.io.FileInputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.Statement; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelToMysql { public static void main(String[] args) { String jdbcURL = "jdbc:mysql://localhost:3306/database_name"; String username = "username"; String password = "password"; String excelFilePath = "path_to_excel_file"; int batchSize = 20; Connection connection = null; try { FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); Workbook workbook = new XSSFWorkbook(inputStream); Sheet firstSheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = firstSheet.iterator(); connection = DriverManager.getConnection(jdbcURL, username, password); connection.setAutoCommit(false); String sql = "INSERT INTO table_name (column1, column2, column3) VALUES (?, ?, ?)"; PreparedStatement statement = connection.prepareStatement(sql); int count = 0; rowIterator.next(); // Skip header row while (rowIterator.hasNext()) { Row nextRow = rowIterator.next(); Iterator<Cell> cellIterator = nextRow.cellIterator(); while (cellIterator.hasNext()) { Cell nextCell = cellIterator.next(); int columnIndex = nextCell.getColumnIndex(); switch (columnIndex) { case 0: String column1Value = nextCell.getStringCellValue(); statement.setString(1, column1Value); break; case 1: String column2Value = nextCell.getStringCellValue(); statement.setString(2, column2Value); break; case 2: double column3Value = nextCell.getNumericCellValue(); statement.setDouble(3, column3Value); break; } } statement.addBatch(); if (count % batchSize == 0) { statement.executeBatch(); } } workbook.close(); statement.executeBatch(); connection.commit(); connection.close(); System.out.println("Data imported successfully."); } catch (Exception e) { e.printStackTrace(); } } } ### 回答3: 导入Excel文件到MySQL数据库的代码可以使用Java中的Apache POI和JDBC来实现。下面是一个示例代码: ```java import java.io.FileInputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelToMySQLImporter { public static void main(String[] args) { String excelFilePath = "your_excel_file_path.xlsx"; String dbUrl = "jdbc:mysql://localhost:3306/your_database"; String username = "your_username"; String password = "your_password"; try (Connection connection = DriverManager.getConnection(dbUrl, username, password); FileInputStream fileInputStream = new FileInputStream(excelFilePath); Workbook workbook = new XSSFWorkbook(fileInputStream)) { Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表 for (Row row : sheet) { int id = (int)row.getCell(0).getNumericCellValue(); // 获取第一列数据 String name = row.getCell(1).getStringCellValue(); // 获取第二列数据 int age = (int)row.getCell(2).getNumericCellValue(); // 获取第三列数据 // 创建插入数据的SQL语句 String insertQuery = "INSERT INTO your_table (id, name, age) VALUES (?, ?, ?)"; PreparedStatement preparedStatement = connection.prepareStatement(insertQuery); preparedStatement.setInt(1, id); preparedStatement.setString(2, name); preparedStatement.setInt(3, age); preparedStatement.executeUpdate(); } System.out.println("数据导入成功!"); } catch (Exception e) { e.printStackTrace(); } } } ``` 请注意替换`your_excel_file_path.xlsx`为实际Excel文件的路径,`your_database`为要导入的数据库的名称,`your_table`为要导入的表的名称,`your_username`和`your_password`为数据库的用户名和密码。代码将依次读取工作表的每一行,并将数据插入到MySQL数据库中。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

daydayup-2016

你的鼓励将是我创作的最大动力哦

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值