XAMPPのMySQL起動不可と修復

PHP

発生事象

XAMPPでのエラー表示内容

Apacheは普通に起動出来たのに、何故かSQLは起動せず・・・

12:56:13 [main] Initializing Control Panel
12:56:13 [main] Windows Version: Home 64-bit
12:56:13 [main] XAMPP Version: 7.4.28
12:56:13 [main] Control Panel Version: 3.3.0 [ Compiled: Apr 6th 2021 ]
12:56:13 [main] Running with Administrator rights – good!
12:56:13 [main] XAMPP Installation Directory: “c:\xampp\”
12:56:13 [main] Checking for prerequisites
12:56:13 [main] All prerequisites found
12:56:13 [main] Initializing Modules
12:56:13 [main] Starting Check-Timer
12:56:13 [main] Control Panel Ready
12:56:16 [Apache] Attempting to start Apache app…
12:56:16 [Apache] Status change detected: running
12:56:18 [mysql] Attempting to start MySQL app…
12:56:18 [mysql] Status change detected: running
12:56:20 [mysql] Status change detected: stopped
12:56:20 [mysql] Error: MySQL shutdown unexpectedly.
12:56:20 [mysql] This may be due to a blocked port, missing dependencies,
12:56:20 [mysql] improper privileges, a crash, or a shutdown by another method.
12:56:20 [mysql] Press the Logs button to view error logs and check
12:56:20 [mysql] the Windows Event Viewer for more clues
12:56:20 [mysql] If you need more help, copy and post this
12:56:20 [mysql] entire log window on the forums

C:\xampp\mysql\data\mysql_error.log

MySQLのエラーログを確認してみると、以下のようなログが出ている。

2022-04-18 12:56:18 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2022-04-18 12:56:18 0 [Note] InnoDB: Uses event mutexes
2022-04-18 12:56:18 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-04-18 12:56:18 0 [Note] InnoDB: Number of pools: 1
2022-04-18 12:56:18 0 [Note] InnoDB: Using SSE2 crc32 instructions
2022-04-18 12:56:18 0 [Note] InnoDB: Initializing buffer pool, total size = 16M, instances = 1, chunk size = 16M
2022-04-18 12:56:18 0 [Note] InnoDB: Completed initialization of buffer pool
2022-04-18 12:56:18 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2022-04-18 12:56:18 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-04-18 12:56:18 0 [Note] InnoDB: Setting file 'C:\xampp\mysql\data\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-04-18 12:56:18 0 [Note] InnoDB: File 'C:\xampp\mysql\data\ibtmp1' size is now 12 MB.
2022-04-18 12:56:18 0 [Note] InnoDB: Waiting for purge to start
2022-04-18 12:56:18 0 [Note] InnoDB: 10.4.24 started; log sequence number 47063; transaction id 8
2022-04-18 12:56:18 0 [Note] InnoDB: Loading buffer pool(s) from C:\xampp\mysql\data\ib_buffer_pool
2022-04-18 12:56:18 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-04-18 12:56:18 0 [Note] InnoDB: Buffer pool(s) load completed at 220418 12:56:18
2022-04-18 12:56:18 0 [Note] Server socket created on IP: '::'.

解決案

破損データの復旧

手順1: MySqlフォルダのバックアップ:非常に重要

復旧失敗したときに、C:\xampp\mysql\dataのデータを再利用がする可能性があるため、

C:\xampp\mysqlをコピペでバックアップします。

手順2: dataフォルダ内の初期テーブルを削除

C:\xampp\mysql\dataから以下のフォルダを削除します。

  • mysql
  • performance_schema
  • phpmyadmin
  • test
  • 自分で作ったデータベース以外のファイル全て

手順3: バックアップフォルダ内のファルダをコピペ

以下のフォルダをC:\xampp\mysql\dataにコピペします。
手順2で削除したものと同じフォルダです。
C:\xampp\mysql\backupはxammp様が定期的に作成してくれています。

  • mysql
  • performance_schema
  • phpmyadmin
  • test
  • ibdata1 

バックアップしたdataフォルダの中からibdata1というファイルをコピーして、XAMPPを終了後にmysql\data内の同名ファイルに上書きしてください。このファイルはデータベースの情報が保存されたファイルらしいので、このファイルを上書きしないとMySQL自体は復旧しても、元のデータベースのテーブルにはアクセスできない状態になるようです。

手順4: MySqlのstart

これでstartできれば完了です。

Port競合

上記の破損データの復旧しても起動できない場合は、Port競合も確認しましょう。

MySQLが使うポート番号「3306番」が他で使われていないか(競合していないか)確認します。XAMPP Control Panelで「Netstat」ボタンをクリックし、表示されるリストの中で3306を使っているものが無いかどうかチェックします。

XAMPP再インストール

データの復旧とPort競合で解決できない場合は、XAMPPを再度インストールするしかないですので、サイトのファイルバックアップとMySqlデータのバックアップしてから実行しましょう。

原因

XAMPPと閉じるときに、異常シャットダウンが発生するとよくある。

今後は必ずXAMPPのApache、MySQLサービスを停止(Stopボタンを押し)してからQuitをクリックしてから、PCシャットダウンする。

コメント

タイトルとURLをコピーしました