Xammp Mysql index 索引错误修复
Mysql修复
我的mysql是xammp集成的mysql,重启时没有提前关闭mysql.导致数据库索引文件错误。
启动时无法启动,
10:35:04 [mysql] Error: MySQL shutdown unexpectedly.
10:35:04 [mysql] This may be due to a blocked port, missing dependencies,
10:35:04 [mysql] improper privileges, a crash, or a shutdown by another method.
10:35:04 [mysql] Press the Logs button to view error logs and check
10:35:04 [mysql] the Windows Event Viewer for more clues
10:35:04 [mysql] If you need more help, copy and post this
10:35:04 [mysql] entire log window on the forums
查看error文件如下:
2020-09-28 10:32:38 0 [Note] InnoDB: Waiting for purge to start
2020-09-28 10:32:38 0 [Note] InnoDB: 10.4.14 started; log sequence number 475704; transaction id 556
2020-09-28 10:32:38 0 [Note] InnoDB: Loading buffer pool(s) from E:\xampp\mysql\data\ib_buffer_pool
2020-09-28 10:32:38 0 [Note] Plugin 'FEEDBACK' is disabled.
2020-09-28 10:32:38 0 [Note] Server socket created on IP: '::'.
2020-09-28 10:32:38 0 [ERROR] mysqld.exe: Table '.\mysql\db' is marked as crashed and should be repaired
2020-09-28 10:32:38 0 [ERROR] mysqld.exe: Index for table '.\mysql\db' is corrupt; try to repair it
2020-09-28 10:32:38 0 [ERROR] Couldn't repair table: mysql.db
2020-09-28 10:32:38 0 [ERROR] Fatal error: Can't open and lock privilege tables: Index for table 'db' is corrupt; try to repair it
2020-09-28 10:32:38 0 [ERROR] Aborting
初步错误判断为索引文件错误。
Index for table '.\mysql\db' is corrupt;
百度了发现几个方案:
1. innodb_force_recovery=1 失败,无效。
找到如下目录xammp
E:\xampp\mysql\data\my.ini
ini文件的[mysqld] 下方插入 innodb_force_recovery=1,后面可选1-6.。
[mysqld]
datadir=c:/xampp/mysql/data
E:\xampp\mysql\data=1
[client]
2 . myisamchk 无效。
打开上面mysql\bin 目录。地址栏输入cmd进入 dos界面。
输入下面的代码:
shell> myisamchk -r mysql.db
-r 表示可以修复大多数错误。
E:\xampp\mysql\bin> myisamchk -r db
myisamchk: error: File 'db' doesn't exist
E:\xampp\mysql\bin>myisamchk -r ./data/db.MYI
myisamchk: error: File './data/db.MYI' doesn't exist
提示找不到 mysql.db,搜索发现我根本没有这个表,这里不理解上面说的table 和database是不是一个东西,因为我根本找不到错误提示的mysql.db这个table。反正就是不行,
3. mysqld 失败
stackflow找到了这个,,还是不行。
从控制面板打开shell,然后使用以下命令启动mysql:
mysqld –-console –-skip-grant-tables –-skip-external-locking
从控制面板中打开另一个外壳,并使用以下命令修复数据库:
mysqlcheck -r --databases mysql --use-frm
停止mysql,关闭shell,然后正常重启mysql
4.替换大法 成功
stackflow上说这个办法,然后马上拷贝backup下面所有文件到 data,替换,然后就好了。
Copy from xampp/mysql/backup folder and paste in xampp/mysql/data folder except ibdata1 file.
如果从xampp / mysql / data替换ibdata1文件,那么您将得到的错误表不存在。