MySQLのMyISAMが混在する環境のバックアップについて注意事項
...※古い記事ですのでご注意ください※
こんにちは。小宮です。社内のMyISAMテーブルが混在しているサービスにて、
mysqldumpによるバックアップに失敗しコールドバックアップを取ったが不整合出たという事件について相談うけまして、
その顛末を記録しがてら注意事項をまとめておきたいと思います。
(昔軽く伝えた記憶があり皆知ってると思ってたんですが、わかりやすさや伝える力と、
私と他の人のmysqlに対する愛のレベルが少し異なるという認識が足らなかったようです。
トラブルは起きるもんだし失敗は挑戦の証で成功の元ですが同じことは繰り返さないようにしないと。)何が大切かって、マスタとスレーブのデータの整合性です。
つまり、
⇒バックアップ対象が絶対に更新されてないこと
⇒バックアップ取得時点のポジションとバイナリログファイル名が明確であること
が超重要です。
MyISAM混在環境では気をつけないと不整合でます。
不整合でると購入したはずのコンテンツが買われてないように見えるなど割と大変なことになりますね。
InnoDBだけなら–single-transactionつけとけば不整合は気にしなくて大丈夫です。・mysqldumpに失敗した原因
mysqldump: Error 1317: Query execution was interrupted when dumping tableこのエラーは、
mysqldumpでデータを読んでる間にクエリーが中断されると出るやつです。Ctrl + Cとかkillでスレッドが殺されたとか。。
(とTwitterで教えていただきました。ありがとうございます。それから、整合性のためにマスタからmysqldumpでデータをとることになったのですが、
その際にslaveでreplicationを止めて更新がない状態でとっている方法をそのまま用いたのも不整合が起きる原因になりました。
(MyISAMが混在する環境なのにFLUSH TABLES WITH READ LOCK;をしてなかった)MyISAMが混在する環境の場合、トランザクションは使えないので、
replicaion停止または共有ロックで更新停止が必要になります。ex) FLUSH TABLES WITH READ LOCK; sleepやsyncでロックが終わる(確実に更新停止される)のを待つ ポジションとファイル名をとりログに記録する mysqldumpする UNLOCK TABLES;特にクエリを中断したりしてない(中断と整合性がごっちゃ)という指摘があったりしてそれは私もよくわからないところですが、
更新されないようにしてれば中断も起きるはずがないので、対処方法は更新を確実に止める一択かと思います。MysqlのHAとトラブル事例
...久しぶりの更新になります。プラットフォームの宮下です。
先日開催されました、July Tech Festa2013というイベントの中の1コマで何と私が発表をさせて頂きました。
その時使用した資料をアップしますので興味のある方は是非一読下さい。[slideshare id=24320385&doc=mysqlha-130716215401-phpapp02]
mysqlのHA構成のデザインパターン紹介を経験談を交えて話させて頂きました。
とても緊張してしまって肝心のトラブル事例がお話出来ませんでした。このブログでは、包み隠さずトラブルのレポートが出来ればと思います。
今回のテーマは、小宮先生のレポートを多分に活用させて頂いています。
次回こそは、私の成果を発表したいもんです。それではまた近いうちに更新します。
瀕死の技術ブログを復旧した話
...こんにちわ。
今回は主に(当ブログの)mysqlデータベース復旧のお話になります。
担当のお方が
「waordpressだとinnodbよりmyisamのほうが早いらしいので、
変える前にinnodbのmy.cnfのパラメータいじくってベンチマークとろうとした」
ことをきっかけにDBのデータがぶっ壊れました。
mysql5.6ならmyisam使わなくても参照専用トランザクション使うよう改造できれば早いらしいよという話はおいといて。(5.5だし)
DBデータが読めなくてwordpressの管理画面にログインできなくなってしまいました。-————————————————– 130528 11:59:24 [ERROR] Missing system table mysql.proxies_priv; please run mysql_upgrade to create it
130528 11:59:24 [ERROR] Native table ‘performance_schema’.’events_waits_current’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.’events_waits_history’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.’events_waits_history_long’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘setup_consumers’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘setup_instruments’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘setup_timers’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘performance_timers’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.’threads’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.’events_waits_summary_by_thread_by_event_name’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.’events_waits_summary_by_instance’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.’events_waits_summary_global_by_event_name’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘file_summary_by_event_name’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘file_summary_by_instance’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘mutex_instances’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘rwlock_instances’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘cond_instances’ has the wrong structure
130528 11:59:24 [ERROR] Native table ‘performance_schema’.‘file_instances’ has the wrong structure
130528 11:59:24 [Note] Event Scheduler: Loaded 0 events
130528 11:59:24 [Note] /usr/libexec/mysqld: ready for connections.
Version: ‘5.5.30-log’ socket: ‘/var/lib/mysql/mysql.sock’ port: 3306 MySQL Community Server (GPL) by Remi
130528 11:59:50 [ERROR] Cannot find or open table xxxxxx_db/dl_options from
the internal data dictionary of InnoDB though the .frm file for the
table exists. Maybe you have deleted and recreated InnoDB data
files but have forgotten to delete the corresponding .frm files
of InnoDB tables, or you have moved .frm files to another database?
or, the table contains indexes that this version of the engine
doesn’t support.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
how you can resolve the problem.);
-————————————————–