Share
Embed
MySQLを学ぶ技術
2020/01/17 DevelopersNight 01
https://gmo.connpass.com/event/160796/
yoku0825
January 17, 2020
Transcript
61 slides
-
\こんばんは/ yoku0825@とある企業のDBA オラクれない ‐ ポスグれない ‐ マイエスキューエる ‐ 生息域 Twitter:
@yoku0825 ‐ Blog: 日々の覚書 ‐ 日本MySQLユーザ会 ‐ MySQL Casual ‐ 2/60 -
\こんばんは/ yoku0825@ とある企業のDBA GMOメディア オラクれない ‐ ポスグれない ‐ マイエスキューエる ‐
生息域 Twitter: @yoku0825 ‐ Blog: 日々の覚書 ‐ 日本MySQLユーザ会 ‐ MySQL Casual ‐ GMO Media, Inc. ‐ 3/60 -
ドキュメントを読もう MySQL 5.6日本語版は「MySQL 5.6.23まで」 MySQL 5.6.23は2015/2/2 :-P ‐ MySQL 5.6の情報でさえ日本語情報を鵜呑みにするのは危険
‐ 日本語で調べて、URLから「自分が本当に調べたいバージョンの英語版リファレン ス」に飛ぶ MySQL :: MySQL 5.6 リファレンスマニュアル :: 14.11 InnoDB とオンライン DDL https://dev.mysql.com/doc/refman/5.6/ja/innodb-online-ddl.html ‐ MySQL :: MySQL 8.0 Reference Manual :: 15.12 InnoDB and Online DDL https://dev.mysql.com/doc/refman/8.0/en/innodb-online-ddl.html ‐ 14/60 -
ドキュメントを読もう リファレンスマニュアル本編の他に “What Is New” と “Release Notes” MySQL ::
MySQL 8.0 Reference Manual :: 1.4 What Is New in MySQL 8.0 ‐ MySQL :: MySQL 8.0 Release Notes ‐ 15/60 -
What Is New MySQLのバージョン番号は、本当はずっと “メジャーバージョン.マイナーバー ジョン.バージョン番号” “メジャーバージョン.マイナーバージョン” の2桁を取って “リリースシリーズ” と読んでいる
MySQL :: MySQL 8.0 Reference Manual :: 2.1.1 Which MySQL Version and Distribution to Install ‐ ドキュメントは “リリースシリーズ” 単位で分冊 実質 “リリースシリーズ” がメジャーバージョンみたいな感じ( だった ) 今はメンテナンスリリースにリリースシリーズ変更ばりの新機能をぶち込んできやがる… ‐ リリースシリーズをまたいだ新機能や非互換のリストはここに多くが含まれている 簡単な説明と、本編へのハイパーリンクが含まれているのでインデックスとして便利 ‐ 16/60 -
Release Notes 開発初期はそのバージョンで実装された新機能が載ったりするけど、一般リリース 以降はバグフィックスノートが主 ( のはずなんだけどなぁ ) MySQL 8.0系は 何故か
メンテナンスリリースで機能が増えるので、粒度が小さい “What Is New” みたいになってる… バグフィックスノートには対応するバグ番号が載ったりもする 自分でレポートしたのが載ってるとテンション上がる ‐ 5桁のバグ番号は オープンなバグトラッキングシステム のもの、8桁のバグ番号は開発者の内 部BTSのもの ‐ 17/60 -
ドキュメントを読もう mysql> HELP START SLAVE; Name: 'START SLAVE' Description: Syntax:
START SLAVE [thread_types] [until_option] [connection_options] [channel_option] thread_types: [thread_type [, thread_type] ... ] thread_type: IO_THREAD | SQL_THREAD .. URL: http://dev.mysql.com/doc/refman/8.0/en/start-slave.html MySQLのHELP構文ってやつ - そろばんのしょ(第3版第2刷) 20/60 -
エラーメッセージを読もう 2018-07-12T00:00:46.520037+09:00 9 [ERROR] [MY-010584] [Repl] Slave SQL for channel
'': E rror 'You have an error in your SQL syntax; check the manual that corresponds to your MyS QL server version for the right syntax to use near 'rank, app_id ) VALUES ( 1, 0, 1, 8660 )' at line 1' on query. Default database: 'xxx'. Query: 'REPLACE INTO t1 ( ki nd, genre, rank, id ) VALUES ( 1, 0, 1, 8660 )', Error_code: MY-001064 23/60 -
エラーメッセージを読もう Slave SQL for channel ‘’: Error You have an
error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 24/60 -
エラーメッセージを読もう Slave SQL for channel ‘’: Error ’’ (空文字列) というチャンネルのSQLスレッドでなんかエラーが起きた
‐ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near SQL構文にエラーがあります。近くで使用する正しい構文については、MySQLサーバーのバー ジョンに対応するマニュアルを確認してください translated by Google翻訳 ‐ 25/60 -
エラーメッセージを読もう Slave SQL for channel ‘’: Error ’’ (空文字列) というチャンネルのSQLスレッドでなんかエラーが起きた
チャンネル .. マルチソースレプリケーション実装(5.7)以降に導入された概念でデフォルトは ‘’ (空文字列) SQLスレッド .. レプリケーションスレーブで動作するスレッド、SQLを実行する役割がある。対義語(?)はI/Oス レッド ‐ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near SQL構文にエラーがあります。近くで使用する正しい構文については、MySQLサーバーのバー ジョンに対応するマニュアルを確認してください translated by Google翻訳 ‐ 26/60 -
エラーメッセージを読もう 用語は押さえておく必要がある 英語版ドキュメントに一通り目を通して(とまでは言わない、3割くらい対訳っぽく参照したこ とがあればなんとなくわかる希ガス) 分からない単語を逐次調べていれば だいたい一度はあた ると思う ‐ 一応用語集もあるからここに載ってればきっとMySQL用語 MySQL
:: MySQL 8.0 Reference Manual :: MySQL Glossary ‐ 27/60 -
エラーメッセージを読もう 2020-01-15T11:45:24.621792+09:00 0 [ERROR] [MY-010520] [Server] Invalid (old?) table or
d atabase name 'user_info#p#pmax' 28/60 -
エラーメッセージを読もう 読んで、意味を何となく理解して初めて、「いや、それは違う」と言える 無効な名前じゃない、だって8.0.13とそれ以前はちゃんと動いてたんだから ‐ MySQL Bugs: #94519: Wrong messages in
error-log when using partition with lower- case-table-names=1 ‐ 30/60 -
エラーメッセージを読もう 2019-05-10T17:24:32.227759+09:00 225846 [Warning] [MY-010897] [Repl] Storing MySQL user n
ame or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information. 31/60 -
エラーメッセージを読もう 2018-07-12T00:00:46.520037+09:00 9 [ERROR] [MY-010584] [Repl] Slave SQL for channel
'': E rror 'You have an error in your SQL syntax; check the manual that corresponds to your MyS QL server version for the right syntax to use near 'rank, app_id ) VALUES ( 1, 0, 1, 8660 )' at line 1' on query. Default database: 'xxx'. Query: 'REPLACE INTO t1 ( ki nd, genre, rank, id ) VALUES ( 1, 0, 1, 8660 )', Error_code: MY-001064 事象である “MySQL レプリケーション 止まる” だと原因が多すぎてググラビリ ティは低い “MySQL シンタックスエラー レプリケーション” だと一発でたどり着けた MySQL :: MySQL 5.6 リファレンスマニュアル :: 17.4.1.25 レプリケーションと予約語 ‐ ちなみにこれ RANK が予約語になった影響で転けたやーつ ‐ 34/60 -
エラーメッセージを読もう 2018-07-12T00:00:46.520037+09:00 9 [ERROR] [MY-010584] [Repl] Slave SQL for channel
'': E rror 'You have an error in your SQL syntax; check the manual that corresponds to your MyS QL server version for the right syntax to use near 'rank, app_id ) VALUES ( 1, 0, 1, 8660 )' at line 1' on query. Default database: 'xxx'. Query: 'REPLACE INTO t1 ( ki nd, genre, rank, id ) VALUES ( 1, 0, 1, 8660 )', Error_code: MY-001064 エラー番号は案外情報が欠落するのでググるにはやりにくい MY-* 形式のメッセージが出るようになったのは8.0から 運良く8.0を使って同じエラーを踏んだ人が日本語で情報を書いていることに期待できるかどうか ‐ 1064 はシンタックスエラーの方のエラー番号で、 10584 の方がスレーブでエラーが発生したエ ラー番号(SQLスレッドとI/Oスレッドの区別はない) 二種類混じってることにぱっと見気付けるかどうか… ‐ 35/60 -
ワーニングも読もう mysql80 11> CREATE DATABASE d2 CHARSET utf8; Query OK,
1 row affected, 1 warning (0.11 sec) mysql80 11> SHOW WARNINGS; +---------+------+----------------------------------------------------------------------- ----------------------------------------------------------------------------------------- -------------+ | Level | Code | Message | +---------+------+----------------------------------------------------------------------- ----------------------------------------------------------------------------------------- -------------+ | Warning | 3719 | 'utf8' is currently an alias for the character set UTF8MB3, but will b e an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. | +---------+------+----------------------------------------------------------------------- ----------------------------------------------------------------------------------------- -------------+ 1 row in set (0.00 sec) 36/60 -
ワーニングも読もう ‘utf8’ is currently an alias for the character set
UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. 「utf8」は現在、文字セットUTF8MB3のエイリアスですが、将来のリリースではUTF8MB4の エイリアスになります。 明確にするためにUTF8MB4の使用を検討してください translated by Google翻訳 ‐ 37/60 -
ワーニングも読もう mysql80 11> CREATE DATABASE d3 CHARSET utf8mb3; Query OK,
1 row affected, 1 warning (0.01 sec) mysql80 11> SHOW WARNINGS; +---------+------+----------------------------------------------------------------------- ----------------------+ | Level | Code | Message | +---------+------+----------------------------------------------------------------------- ----------------------+ | Warning | 1287 | 'utf8mb3' is deprecated and will be removed in a future release. Pleas e use utf8mb4 instead | +---------+------+----------------------------------------------------------------------- ----------------------+ 1 row in set (0.00 sec) 38/60 -
ワーニングも読もう ‘utf8mb3’ is deprecated and will be removed in a
future release. Please use utf8mb4 instead 「utf8mb3」は非推奨であり、将来のリリースで削除される予定です。 代わりにutf8mb4を使 用してください translated by Google翻訳 ‐ 39/60 -
試そう ex. “information_schema.tables の data_length + index_length と実際の .ibd ファイルはどれくらい違いがありますか?”
$ ll /usr/mysql/8.0.19/data/sbtest/sbtest1.ibd -h -rw-r----- 1 yoku0825 yoku0825 29M Jan 17 12:41 /usr/mysql/8.0.19/data/sbtest/sbtest1.ibd mysql80 19> SELECT table_schema, table_name, format_bytes(data_length + index_length) AS size FROM information_schema.tables WHERE table_schema = 'sbtest'; +--------------+------------+-----------+ | TABLE_SCHEMA | TABLE_NAME | size | +--------------+------------+-----------+ | sbtest | sbtest1 | 23.06 MiB | +--------------+------------+-----------+ 1 row in set (0.01 sec) 43/60 -
試そう ex. “information_schema.tables の data_length + index_length と実際の .ibd ファイルはどれくらい違いがありますか?”
$ ll /usr/mysql/8.0.19/data/sbtest/sbtest*.ibd -h -rw-r----- 1 yoku0825 yoku0825 29M Jan 17 12:42 /usr/mysql/8.0.19/data/sbtest/sbtest1.ibd -rw-r----- 1 yoku0825 yoku0825 29M Jan 17 12:43 /usr/mysql/8.0.19/data/sbtest/sbtest2.ibd -rw-r----- 1 yoku0825 yoku0825 29M Jan 17 12:43 /usr/mysql/8.0.19/data/sbtest/sbtest3.ibd mysql80 21> SELECT table_schema, table_name, format_bytes(data_length + index_length) AS size FROM information_schema.tables WHERE table_schema = 'sbtest'; +--------------+------------+-----------+ | TABLE_SCHEMA | TABLE_NAME | size | +--------------+------------+-----------+ | sbtest | sbtest1 | 23.06 MiB | | sbtest | sbtest2 | 23.06 MiB | | sbtest | sbtest3 | 16.00 KiB | +--------------+------------+-----------+ 3 rows in set (0.01 sec) 44/60 -
試そう ex. “information_schema.tables の data_length + index_length と実際の .ibd ファイルはどれくらい違いがありますか?”
mysql80 21> ANALYZE TABLE sbtest.sbtest3; +----------------+---------+----------+----------+ | Table | Op | Msg_type | Msg_text | +----------------+---------+----------+----------+ | sbtest.sbtest3 | analyze | status | OK | +----------------+---------+----------+----------+ 1 row in set (0.04 sec) mysql80 21> SELECT table_schema, table_name, format_bytes(data_length + index_length) AS size FROM information_schema.tables WHERE table_schema = 'sbtest'; +--------------+------------+-----------+ | TABLE_SCHEMA | TABLE_NAME | size | +--------------+------------+-----------+ | sbtest | sbtest1 | 23.06 MiB | | sbtest | sbtest2 | 23.06 MiB | | sbtest | sbtest3 | 23.06 MiB | +--------------+------------+-----------+ 3 rows in set (0.00 sec) 45/60 -
試そう ex. “information_schema.tables の data_length + index_length と実際の .ibd ファイルはどれくらい違いがありますか?”
$ ll /usr/mysql/8.0.19/data/sbtest/sbtest*.ibd -h -rw-r----- 1 yoku0825 yoku0825 240M Jan 17 12:45 /usr/mysql/8.0.19/data/sbtest/sbtest1.ib d mysql80 23> SELECT table_schema, table_name, format_bytes(data_length + index_length) AS size FROM information_schema.tables WHERE table_schema = 'sbtest'; +--------------+------------+------------+ | TABLE_SCHEMA | TABLE_NAME | size | +--------------+------------+------------+ | sbtest | sbtest1 | 214.70 MiB | +--------------+------------+------------+ 1 row in set (0.04 sec) 46/60 -
試そう ex. “information_schema.tables の data_length + index_length と実際の .ibd ファイルはどれくらい違いがありますか?”
このケースだと2割くらい? ‐ ただし ANALYZE TABLE 前のようなよくわからない状態になったりもする これはInnoDBの統計情報を更新するスレッドがバックグラウンドで非同期で動いているからなんですがそれは置い ておいて ‐ 47/60 -
試そう Not “information_schema.tables の data_length + index_length と実際 の .ibdファイルはどれくらい違いがありますか?”
But “information_schema.tables の data_length + index_length と実際 の .ibdファイルの違いはどこを見ればわかりますか?” 48/60 -
試そう $ ll /usr/mysql/8.0.19/data/sbtest/sbtest*.ibd -h -rw-r----- 1 yoku0825 yoku0825 29M
Jan 17 14:11 /usr/mysql/8.0.19/data/sbtest/sbtest1.ibd -rw-r----- 1 yoku0825 yoku0825 29M Jan 17 14:12 /usr/mysql/8.0.19/data/sbtest/sbtest2.ibd -rw-r----- 1 yoku0825 yoku0825 29M Jan 17 14:12 /usr/mysql/8.0.19/data/sbtest/sbtest3.ibd mysql80 27> ANALYZE TABLE sbtest.sbtest2; +----------------+---------+----------+----------+ | Table | Op | Msg_type | Msg_text | +----------------+---------+----------+----------+ | sbtest.sbtest2 | analyze | status | OK | +----------------+---------+----------+----------+ 1 row in set (0.01 sec) mysql80 26> SELECT table_schema, table_name, format_bytes(data_length + index_length) AS size FROM information_sche ma.tables WHERE table_schema = 'sbtest'; +--------------+------------+-----------+ | TABLE_SCHEMA | TABLE_NAME | size | +--------------+------------+-----------+ | sbtest | sbtest1 | 23.06 MiB | | sbtest | sbtest2 | 32.00 KiB | | sbtest | sbtest3 | 23.06 MiB | +--------------+------------+-----------+ 3 rows in set (0.01 sec) 49/60 -
試そう mysql80 28> SELECT COUNT(*) FROM sbtest.sbtest2; +----------+ | COUNT(*)
| +----------+ | 0 | +----------+ 1 row in set (0.00 sec) mysql80 28> SELECT table_schema, table_name, format_bytes(data_length + index_length + da ta_free) AS size FROM information_schema.tables WHERE table_schema = 'sbtest'; +--------------+------------+-----------+ | TABLE_SCHEMA | TABLE_NAME | size | +--------------+------------+-----------+ | sbtest | sbtest1 | 25.06 MiB | | sbtest | sbtest2 | 25.03 MiB | | sbtest | sbtest3 | 25.06 MiB | +--------------+------------+-----------+ 3 rows in set (0.00 sec) 50/60 -
試そう 最低限、すぐに触れて自分の好きにできる mysqld が必要 Linuxの方が( mysqld の外側から取れる)情報(のノウハウ)は多いからLinuxの方が良い気はする ‐ そういう用途ではパッケージもの(rpm, dpkg)が便利だと思う
MySQL :: Download MySQL Yum Repository ‐ MySQL :: Download MySQL APT Repository ‐ 52/60 -
知識をアップデートしよう 詳解MySQL 5.7 止まらぬ進化に乗り遅れないためのテクニカルガイド (NEXT ONE) | 奥野 幹也 |本
| 通販 | Amazon 実践ハイパフォーマンスMySQL 第3版 | Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, 菊池 研自, 株式会社クイープ |本 | 通販 | Amazon SQLアンチパターン | Bill Karwin, 和田 卓人, 和田 省二, 児島 修 |本 | 通販 | Amazon 56/60 -
知識をアップデートしよう Yoshiaki Yamasaki(@yyamasaki1)さん / Twitter 私市智美 Tomomi Kisaichi(@kisaichi)さん / Twitter
lefred(@lefred)さん / Twitter 57/60 -
知識をアップデートしよう MySQL Casual - connpass Join mysql-casual on Slack! ‐
MySQL Weekly 58/60