LoginSignup
2
4

More than 5 years have passed since last update.

mysqlが死んだ日

Posted at

mysqlが死んだ日

2016/6/27 (月)
projyct E 6月末リリース予定

前兆

前々からファンが大きめの音を立てたり、
ターミナルやクロームがたまに落ちたりしていました。tyousiwarui.png (12.7 kB)

事件発生時

早朝最新devをpullしlocal:3000にアクセスすると
「Can't connect to local MySQL server through socket」

mysql.server status
...not runnning

事件発生時

mysql.server start
... //ザワ

事件発生時

mysql.server start
..................................... //ザワザワ

事件発生時

mysql.server start
...................................... 
...........................
ERROR! The server quit without updating PID file (/usr/local/var/mysql/FL1-125-198-93-19.tky.mesh.ad.jp.pid).

事件発生時

壊れた・・・・。

zrtsubou.jpg (42.5 kB)

対応方法

ERROR! The server quit without updating PID file (~).

2016-06-27T08:45:45.200790Z 0 [Note] /usr/local/Cellar/mysql/5.7.13/bin/mysqld (mysqld 5.7.13) starting as process 11693 ... 
2016-06-27T08:45:45.203400Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2016-06-27T08:45:45.206702Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-06-27T08:45:45.206725Z 0 [Note] InnoDB: Uses event mutexes
2016-06-27T08:45:45.206731Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2016-06-27T08:45:45.206738Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-06-27T08:45:45.207155Z 0 [Note] InnoDB: Number of pools: 1
2016-06-27T08:45:45.207280Z 0 [Note] InnoDB: Using CPU crc32 instructions
2016-06-27T08:45:45.208831Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-06-27T08:45:45.222086Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-06-27T08:45:45.234562Z 0 [Note] InnoDB: The first innodb_system data file 'ibdata1' did not exist. A new tablespace will be created!
2016-06-27T08:45:45.234804Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2016-06-27T08:45:45.234849Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2016-06-27T08:45:45.234868Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2016-06-27T08:45:45.234882Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.

対応方法

ERROR! The server quit without updating PID file (~).

ログ監視

tail -f /usr/local/var/mysql/FL1-125-198-93-19.tky.mesh.ad.jp.err

コレの[Note] = 報告 [Warning] = 警告 [ERROR] = 原因
の[ERROR] を見ます

実行の末行は

mysqld_safe mysqld from pid file /usr/local/var/mysql/〜.pid ended

今回のエラー

InnoDB: Cannot open datafile './ibdata1'
InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
他数行

訳:ibdata1が開けない
訳:システム表領域を作成できませんでした。innodb_data_file_pathを変えるか書き込みをやめてください
訳:0の書き込みを行いました。しかし、注意してください、あなたの貴重なデータが含まれている古いデータファイルを削除しないでください!
→恐らく「容量」がでかすぎて死んだ

今回の場合いい手がない

今回の場合いい手がない設定をいじると別のエラーがエグい出てくる
再起動mysqlを入れなおししました。
→続きは、その時出てきたエラーを紹介

Cannot open datafile './ibdata1'

ibdata1 とは

MySQLのストレージエンジン(InnoDB)は、ファイルにデータを保存・蓄積をibdata1にしています。

/usr/local/var/mysql/ibdata1//データのデフォルト
/usr/local/var/mysql/ib_logfile0 //ログのデフォルト
/usr/local/var/mysql/ib_logfile1//ログのデフォルト

こんなことになる前に

データ最適化を定期的に行う
http://www.mk-mode.com/octopress/2013/08/03/mysql-innodb-optimization/

よくあるエラー

権限をかえたら、ib~が開けない

InnoDB: Unable to lock ./ibdata1

訳:ロックできないです(ファイルを開くための)

mv ibdata1 ibdata1.bad
cp ibdata1.bad ibdata1

設定を変えたら、ib_logfileの容量の大きさが違う

log file ib_logfile0 is of different size XXX XXX bytes

訳:ib_logfile0のサイズがXXXbytesでなくXXXになっています。

rm ib_logfile0 ib_logfile1 //ログなので削除して問題ありません。

よくあるエラー

設定を変えたら

Can't start server: Bind on TCP/IP port: Address already in use
Do you already have another mysqld server running on port: 3306 ?

訳:既に動いているのあるから、新しい設定でスタートできません。

ps -ef | grep mysql
kill -9 XXXX //プロセルID

既に起動しているのもをkillしてください。

よくあるエラー

まれに、mysql.server startしたら、mysqld_safeはうごいて、
mysqldがコケるという事がります。
mysql.server stopします。(killしても無限復活しました。)
http://open-groove.net/mysql/mysqld-mysqldsafe/

px | grep mysql 

では何も出ないのに

ps -ef | grep mysql

したらmysqld_safeが動いていることがわかる。

psオプション

なし コマンドを実行した端末に関するプロセスのみを表示します。
-e すべてのプロセスを表示します。
-f 完全フォーマットで表示します。

よくあるエラー

Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

詰みです。
my.confをいじったり
mysqld --initializeコマンドにオプションを付け進めることができますが、
結構根が深いため、消して入れなおしたほうが早い

最終的に

sudo brew uninstall mysql
再起動
brew install mysql
mysqlのパスを通す
mysql.server start

結論

PCは仕事道具なので、日々メンテナンスをしましょう。
たまに再起動をかけたり、ディスプレイやキーボードを磨いたり、
余分なファイルを消したり、感謝の言葉を伝えたりしましょう。
なんだかんだ行って、っこまったら入れなおしが最強なきがする。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4