XAMPP的MySQL数据库无法启动的解决方案

软件开发大郭
0 评论
/
9 阅读
/
5177 字
23 2023-11

由于电脑强制关机,当我第二次启动的时候,数据库就无法启动了,界面上报下面的错误

错误信息

15:26:52  [mysql]     Error: MySQL shutdown unexpectedly.
15:26:52  [mysql]     This may be due to a blocked port, missing dependencies, 
15:26:52  [mysql]     improper privileges, a crash, or a shutdown by another method.
15:26:52  [mysql]     Press the Logs button to view error logs and check
15:26:52  [mysql]     the Windows Event Viewer for more clues
15:26:52  [mysql]     If you need more help, copy and post this
15:26:52  [mysql]     entire log window on the forums
15:27:21  [mysql]     Status change detected: running

问题定位

查看了错误日志,无法看到任何报错信息。

后来在data目录发现了:mysql/data/DESKTOP-xxx.err

2023-11-23 14:25:14 0 [Note] InnoDB: Loading buffer pool(s) from c:\xampp\mysql\data\ib_buffer_pool
2023-11-23 14:25:14 0 [Note] Plugin 'FEEDBACK' is disabled.
2023-11-23 14:25:14 0 [Note] InnoDB: Buffer pool(s) load completed at 231123 14:25:14
2023-11-23 14:25:14 0 [Note] Server socket created on IP: '::'.
2023-11-23 14:25:14 0 [ERROR] mysqld.exe: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
2023-11-23 14:25:14 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
2023-11-23 14:25:14 0 [ERROR] Aborting

这是mysql的权限相关表损坏了,只要跳过了这个权限表,应该就能正常启动

解决方案

第一步 先启动服务

通过界面上右边上面第三个 Shell功能 ,在弹出黑框命令行中执行下面命令跳过权限启动


mysql\bin\mysqld  --defaults-file=mysql\bin\my.ini --standalone --skip-grant-tables

如果觉得有必要,可以复制一份xampp目录下的mysql_start.bat修改下改成mysql_safe_start.bat mysql_safe_start.bat内容如下:

@echo off
cd /D %~dp0
echo Diese Eingabeforderung nicht waehrend des Running beenden
echo Please dont close Window while MySQL is running
echo MySQL is trying to start
echo Please wait  ...
echo MySQL is starting with mysql\bin\my.ini (console)

mysql\bin\mysqld  --defaults-file=mysql\bin\my.ini --standalone --skip-grant-tables

if errorlevel 1 goto error
goto finish

:error
echo.
echo MySQL konnte nicht gestartet werden
echo MySQL could not be started
pause

:finish

这样子在shell中只要执行mysql_safe_start就能启动了。 启动结果


grabbyte@DESKTOP-xxx c:\xampp
# mysql_safe_start
Diese Eingabeforderung nicht waehrend des Running beenden
Please dont close Window while MySQL is running
MySQL is trying to start
Please wait  ...
MySQL is starting with mysql\bin\my.ini (console)

第二步 修复相关表

现在第二步就是要修复好db

在 MySQL 5.7 及更新的版本以及 MariaDB 10 版本中,mysql.db 表被废弃,而且通常情况下并不建议手动删除。然而,如果你确实需要重建这个表,以下是 mysql.db 表在 MySQL 5.7 和 MariaDB 10 中的结构:

我用repaire相关语句都无法修复,由于这个表在mysql5.7之后就由user表代替了,而我的是mariadb10,所以我直接将表删除,然后重建了,在重启服务器 问题解决:

CREATE TABLE `db` (
  `Host` CHAR(60) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Db` CHAR(64) COLLATE utf8_bin NOT NULL DEFAULT '',
  `User` CHAR(16) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Select_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Insert_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Update_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Delete_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Create_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Drop_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Grant_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `References_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Index_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Alter_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Create_tmp_table_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Lock_tables_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Create_view_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Show_view_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Create_routine_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Alter_routine_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Execute_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Event_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  `Trigger_priv` ENUM('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
  PRIMARY KEY (`Host`,`Db`,`User`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Database privileges';
标签:
    暂无数据