GA

2023/02/08

インデックス vs InnoDBログ書き込みのサイズ観測

TL;DR

  • セカンダリーキーは意外とログ書き込みに響く。無駄なやつをなるべく消したりマージできたりするといいかも。

  • ナチュラルキーを使うのは書き込み面では誤差か。

    • 読み取りで差が出るといいなと思うけれど今日はやらない。
tablesizesize_vs_t1lsnlsn_vs_t1comment
t113,631,4881.0031,977,6821.00auto_increment PK + 0 key
t217,825,7921.3135,158,2931.10auto_increment PK + 1 key
t319,922,9441.4638,051,5391.19auto_increment PK + 2 key
t415,728,6401.1533,413,6341.04natural PK + 0 key
t519,922,9441.4637,070,7121.16natural PK + 1 key



MySQL 8.0.23を用意。


$ bin/mysqld --no-defaults --initialize-insecure --datadir=/tmp/data --lower_case_table_names=1 --log-error-verbosity=3

$ bin/mysqld --no-defaults --datadir=/tmp/data --lower_case_table_names=1 --log-error-verbosity=3 --daemonize
mysqld will log errors to /tmp/data/host.err
mysqld is running as pid 14865

テスト用のテーブルその1。AUTO_INCREMENTがPRIMARY KEYで他のインデックスなし。

mysql> CREATE TABLE d1.t1 (
    ->   num BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   user_id INT UNSIGNED NOT NULL,
    ->   something_id INT UNSIGNED NOT NULL,
    ->   something_count INT UNSIGNED NOT NULL,
    ->   updated DATETIME DEFAULT CURRENT_TIMESTAMP,
    ->   PRIMARY KEY(num)
    -> );
Query OK, 0 rows affected (0.03 sec)

データロード後にチェンジバッファのマージでLSNが進むのが嫌なのでチェンジバッファはOFFに。

mysql> SET GLOBAL innodb_change_buffering = none;
Query OK, 0 rows affected (0.00 sec)

i_s.innodb_metrics の log_lsn_current が有効になってなかったので有効化。

mysql> SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current';
+-----------------+-------+----------+
| name            | count | status   |
+-----------------+-------+----------+
| log_lsn_current |     0 | disabled |
+-----------------+-------+----------+
1 row in set (0.00 sec)

mysql> SET GLOBAL innodb_monitor_enable = 'log_lsn_current';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current';
+-----------------+----------+---------+
| name            | count    | status  |
+-----------------+----------+---------+
| log_lsn_current | 18040637 | enabled |
+-----------------+----------+---------+
1 row in set (0.00 sec)

で、データをロード。

$ perl -MDBI -E 'my $conn= DBI->connect("dbi:mysql:d1;mysql_socket=/tmp/mysql.sock", "root", ""); for (my $something_id= 1; $something_id <= 100; $something_id++) { for (my $user_id= 1; $user_id <= 1000; $user_id++) { $conn->do("INSERT INTO t1 VALUES (NULL, ?, ?, 1, NOW())", undef, $user_id, $something_id) } }'

$ bin/mysql -e "SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current'"
+-----------------+----------+---------+
| name            | count    | status  |
+-----------------+----------+---------+
| log_lsn_current | 50018319 | enabled |
+-----------------+----------+---------+

進んだLSNは 31,977,682 。次。

mysql> CREATE TABLE d1.t2 (
    ->   num BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   user_id INT UNSIGNED NOT NULL,
    ->   something_id INT UNSIGNED NOT NULL,
    ->   something_count INT UNSIGNED NOT NULL,
    ->   updated DATETIME DEFAULT CURRENT_TIMESTAMP,
    ->   PRIMARY KEY(num),
    ->   KEY idx_userid (user_id)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current';
+-----------------+----------+---------+
| name            | count    | status  |
+-----------------+----------+---------+
| log_lsn_current | 50037236 | enabled |
+-----------------+----------+---------+
1 row in set (0.00 sec)

セカンダリーキーを1個増やしたバージョン。

$ perl -MDBI -E 'my $conn= DBI->connect("dbi:mysql:d1;mysql_socket=/tmp/mysql.sock", "root", ""); for (my $something_id= 1; $something_id <= 100; $something_id++) { for (my $user_id= 1; $user_id <= 1000; $user_id++) { $conn->do("INSERT INTO t2 VALUES (NULL, ?, ?, 1, NOW())", undef, $user_id, $something_id) } }'

$ bin/mysql -e "SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current'"
+-----------------+----------+---------+
| name            | count    | status  |
+-----------------+----------+---------+
| log_lsn_current | 85195529 | enabled |
+-----------------+----------+---------+

35,158,293 次。

mysql> CREATE TABLE d1.t3 (
    ->   num BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   user_id INT UNSIGNED NOT NULL,
    ->   something_id INT UNSIGNED NOT NULL,
    ->   something_count INT UNSIGNED NOT NULL,
    ->   updated DATETIME DEFAULT CURRENT_TIMESTAMP,
    ->   PRIMARY KEY(num),
    ->   KEY idx_userid (user_id),
    ->   KEY idx_updated (updated)
    -> );
Query OK, 0 rows affected (0.04 sec)

mysql> SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current';
+-----------------+----------+---------+
| name            | count    | status  |
+-----------------+----------+---------+
| log_lsn_current | 85218863 | enabled |
+-----------------+----------+---------+
1 row in set (0.00 sec)

更に追加でもう一つセカンダリーキー。

$ perl -MDBI -E 'my $conn= DBI->connect("dbi:mysql:d1;mysql_socket=/tmp/mysql.sock", "root", ""); for (my $something_id= 1; $something_id <= 100; $something_id++) { for (my $user_id= 1; $user_id <= 1000; $user_id++) { $conn->do("INSERT INTO t3 VALUES (NULL, ?, ?, 1, NOW())", undef, $user_id, $something_id) } }'

$ bin/mysql -e "SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current'"
+-----------------+-----------+---------+
| name            | count     | status  |
+-----------------+-----------+---------+
| log_lsn_current | 123270402 | enabled |
+-----------------+-----------+---------+

38,051,539 。少なくともファイルサイズほど大きくは増えない。

$ ll d1
total 50188
-rw-r----- 1 yoku0825 yoku0825 13631488 Feb  8 00:33 t1.ibd
-rw-r----- 1 yoku0825 yoku0825 17825792 Feb  8 00:39 t2.ibd
-rw-r----- 1 yoku0825 yoku0825 19922944 Feb  8 00:44 t3.ibd

4つめ。 (user_id, something_id) のナチュラルキー風。カラムの数を変えないために num は自分で詰める。 $user_id のループを内側にしてあるのでPRIMARY KEYのランダムインサート状態になる。
PKが user_id の検索に使えるので実質 t2 プラスアルファ状態。

mysql> CREATE TABLE d1.t4 (
    ->   num BIGINT UNSIGNED NOT NULL,
    ->   user_id INT UNSIGNED NOT NULL,
    ->   something_id INT UNSIGNED NOT NULL,
    ->   something_count INT UNSIGNED NOT NULL,
    ->   updated DATETIME DEFAULT CURRENT_TIMESTAMP,
    ->   PRIMARY KEY(user_id, something_id)
    -> );
Query OK, 0 rows affected (0.05 sec)

mysql> SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current';
+-----------------+-----------+---------+
| name            | count     | status  |
+-----------------+-----------+---------+
| log_lsn_current | 123287410 | enabled |
+-----------------+-----------+---------+
1 row in set (0.00 sec)

$ perl -MDBI -E 'my $conn= DBI->connect("dbi:mysql:d1;mysql_socket=/tmp/mysql.sock", "root", ""); my $n= 1; for (my $something_id= 1; $something_id <= 100; $something_id++) { for (my $user_id= 1; $user_id <= 1000; $user_id++) { $conn->do("INSERT INTO t4 VALUES (?, ?, ?, 1, NOW())", undef, $n++, $user_id, $something_id) } }'

$ bin/mysql -e "SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current'"
+-----------------+-----------+---------+
| name            | count     | status  |
+-----------------+-----------+---------+
| log_lsn_current | 156701044 | enabled |
+-----------------+-----------+---------+

33,413,634 。セカンダリーキーを足してラスト。

mysql> CREATE TABLE d1.t5 (
    ->   num BIGINT UNSIGNED NOT NULL,
    ->   user_id INT UNSIGNED NOT NULL,
    ->   something_id INT UNSIGNED NOT NULL,
    ->   something_count INT UNSIGNED NOT NULL,
    ->   updated DATETIME DEFAULT CURRENT_TIMESTAMP,
    ->   PRIMARY KEY(user_id, something_id),
    ->   KEY idx_updated(updated)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current';
+-----------------+-----------+---------+
| name            | count     | status  |
+-----------------+-----------+---------+
| log_lsn_current | 156720509 | enabled |
+-----------------+-----------+---------+
1 row in set (0.00 sec)

$ bin/mysql -e "SELECT name, count, status FROM information_schema.innodb_metrics WHERE name = 'log_lsn_current'"
+-----------------+-----------+---------+
| name            | count     | status  |
+-----------------+-----------+---------+
| log_lsn_current | 193791221 | enabled |
+-----------------+-----------+---------+

37,070,712 。実質 t3 相当で似たようなLSN。

で、冒頭の表再掲。

table size size_vs_t1 lsn lsn_vs_t1 comment
t1 13,631,488 1.00 31,977,682 1.00 auto_increment PK + 0 key
t2 17,825,792 1.31 35,158,293 1.10 auto_increment PK + 1 key
t3 19,922,944 1.46 38,051,539 1.19 auto_increment PK + 2 key
t4 15,728,640 1.15 33,413,634 1.04 natural PK + 0 key
t5 19,922,944 1.46 37,070,712 1.16 natural PK + 1 key
​

2022/12/19

見えるバグレポート、見えないバグレポート、そもそもbugs.mysql.comじゃないバグレポート

この記事は MySQL闇歴史 Advent Calendar 2022 の2枚目の19日目です。

知名度:★★☆☆☆
闇度 :★☆☆☆☆
見えないという意味での闇度:★★★☆☆


TL;DR

  • リリースノートなどに現れる、整数8桁のバグIDのものは中の人にしか見られない
  • 整数1~6桁のバグIDはbugs.mysql.comで検索できるかも知れない、ただしセキュリティイシューを除く

まずMySQLには2種類のバグトラッカーがあるらしい。

  • みんなだいすき(?) bugs.mysql.com
  • MySQLの中の人だけで使われているバグトラッカー(どっかのbugs.mysql.comのエントリでURLが一瞬出てた気がするけど見失ったし、どうせVPNとかないとアクセスできない)

bugs.mysql.comでない、中の人の使うバグトラッカーはIDが8桁(これは俺がMySQLに目覚めた時からそうだった)の整数だったので、俺は「8桁Bugs」と呼んでいる。
今が3400万くらいの数字になっているようなので、まだしばらくは8桁Bugsのまま呼び方を変える必要はありそうにない。

bugs.mysql.comに投稿した時に「Duplicate of 8桁Bugs」みたいな書き方をされたり、リリースノートのBugs Fixedの欄に8桁Bugsが現れたりする。

MySQL :: MySQL 8.0 Release Notes :: Changes in MySQL 8.0.31 (2022-10-11, General Availability)

GitHubのコミットメッセージにはよく8桁BugsのIDが記載されているので、リリースノートを見て8桁だなと思ったらGitHubの方から検索してみると再現条件などの情報が当たれるかも知れない。

https://github.com/mysql/mysql-server/search?q=34361827&type=commits

bugs.mysql.comのコミュニティレポートが8桁Bugsに転記されているフシもあって、自分のレポートした番号がリリースノートでは別の番号で記載されていることもたまにある。
これが「そもそもbugs.mysql.comじゃないバグレポート」。


コミュニティユースの bugs.mysql.com に投稿するとオートインクリメント(?)なバグIDが付与され、一部の人にだけ人気な Bug#2 Does not make Toast の1桁から最近では6桁の10万9千番台まで来ている。

6桁である Bug#100000 Provide an index hint that only affects the choice of index for NL join に到達したのは2020年の6月。

それまで5桁の期間が長かったので、俺はよく「5桁Bugs」なんて呼んでいた(今は「6桁Bugs」と呼んでいる)。

これが通常「見えるバグレポート」

その一方で、レポートする側が「明らかにこれは特別な権限が無くてもMySQLを落とせるバグ」みたいなものを衆目から隠すためにのフラグがある。

このフラグが立つと、かの有名(?)な You do not have access to bug #6桁Bugs 状態になる。レポートする本人が立てなくても、中の人が深刻度を加味してフラグが立てられることもある。

ちなみに、 You do not have access to bug になっても、レポートした本人にだけは見えたりする。

https://bugs.mysql.com/bug.php?id=104784 (俺と中の人以外はこのURLが You do not have access to になるはず)

これが「見えないバグレポート」。

6桁Bugsと8桁Bugsで探す場所が違ったり、探しても見えないものがあったりなので覚えておくと必要になった時に迷わない(諦めがつく)かも。

​

2022/12/18

ST_FIELD_INFO の順番がやっと何のことだか理解したはなし

このエントリは MySQL Advent Calendar 2022 の17日目の記事です。


TL;DR

昔誰かが「information_schemaプラグインを書きたくなるのはMySQLユーザーの麻疹(はしか)みたいなもん」と言っていて、なるほど誰でも確かに一度は通る道(MySQLのプラグインの中では一番書くのが楽)かなあと思って俺も嗜んだりする。

基本的には↓を写経するだけで骨格は掴める。というかこれだけでやってきた(というほどは書いてないけど)

MySQL :: Extending MySQL 8.0 :: 4.4.6 Writing INFORMATION_SCHEMA Plugins

久々にちょっと(MySQL 8.0になって初めて) 試してみたのが簡単に mysqld自身のPIDを返すだけ のもの。

しかしよく考えたら今まで写経しかしてこなかったので、イマイチST_FIELD_INFOのことをよくわかっていない。

という訳でググったら https://dev.mysql.com/doc/dev/mysql-server/latest/structST__FIELD__INFO.html が出てきた。

せじまさんが褒めちぎっていた理由がやっとわかった気がする。これは便利。

​

2022/12/14

Re: MySQL 5.6.9のmysqlクライアントがujis, sjis, cp932で落ちる(5.6.12で修正)

この記事は MySQL闇歴史のカレンダー | Advent Calendar 2022 の2枚目の14日目の記事です。

TL;DR

知名度:★☆☆☆☆
(俺の心の)闇度 :★★★★☆
UTF-8以外はやめた方が良いよ度:★★★★★


古いやつでも Docker Hub から持ってこられるかなと思ったら、5.6は5.6.25とそれ以降しかなかった(´・ω・`)

仕方ないのでアーカイブから引っ張ってきて展開。

# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
# tar xf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
# mv -i mysql-5.6.10-linux-glibc2.5-x86_64/ /usr/local/mysql
# cd /usr/local/mysql
# useradd mysql
# ./scripts/mysql_install_db --user=mysql
# ./support-files/mysql.server start
# bin/mysql --default-character-set=ujis
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> status;
Segmentation fault (core dumped)

御覧の通り(?)、MySQL 5.6.11とそれ以前では --default-character-set=ujis (sjisでも)で何かを打ち込むと「 mysql コマンドラインクライアントが」クラッシュする。

# file core.230
core.230: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from 'bin/mysql --default-character-set=ujis', real uid: 0, effective uid: 0, real gid: 0, effective gid: 0, execfn: 'bin/mysql', platform: 'x86_64'

ちゃんとコマンドラインクライアントのコアファイル。

このクラッシュが何故なのかは(もう直ってるし)どうでも良いにせよ、これで生まれた心の闇はこんな感じ

  • Release Candidateだけど落ちたorz
  • 最初のGeneral Availability(5.6.10)では直らなかった
  • ujis, sjisなんて世界から見れば小さなもんで、それ用にテストされているなんて期待はできない

ちなみにこの時期2013年1月というのは この会社 に勤め始めてちょっとの時期だったので、5.6を新規導入しようと色々調べていた時期だったんだろうなあと思います(その更に前の職の時だったような気もしたんだけど気のせいだったようだ…)

まあそうなんだよなと理解はできるんですが、日本人ユーザーとしてはちょっともんにょりした過去のバグなのでした!

​

2022/12/09

また今年もConoHaの上でMySQLをビルドする季節がやってきた

この記事は ConoHaのカレンダー | Advent Calendar 2022 - Qiita の9日目の記事で、 MySQLのカレンダー | Advent Calendar 2022 - Qiita の9日目の記事でもあります。

去年は失敗したCentOS 9 Streamでのビルドを今年は成功させました。

去年には MySQL :: Supported Platforms: MySQL Database に載っていなかった気がするCentOS 9 Stream(Streamとは書いてないな…)も今は記述があって、8.0はサポートされている様子。


$ cat /etc/centos-release

CentOS Stream release 9

去年 のCentOS 8 Streamでリポジトリ名が小文字になってハマったpowertools, 9 Streamではどうやら crb なるリポジトリに移った様子。

yum - How to get epel-release / epel-release-next / powertools in CentOS Stream 9 - Unix & Linux Stack Exchange

先人の記録に感謝しながらビルドに必要な一式をインストール。

$ sudo dnf install --enablerepo=crb cmake gcc gcc-c++ openssl-devel ncurses-devel libtirpc-devel rpcgen

MySQLのソースコードを落として展開。

$ wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.31.tar.gz
$ tar xf mysql-boost-8.0.31.tar.gz

ビルド用のディレクトリを掘ってcmake。

$ mkdir build
$ cd build/

$ cmake -DWITH_BOOST=../mysql-8.0.31/boost ../mysql-8.0.31

OOM Killerにやられてもアレなので、swapファイルを足しておく。

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile

で、make。ちょっとバイナリのサイズ小さくなってる?

$ time make

real    245m46.514s
user    195m49.156s
sys     20m46.145s

$ sudo make install
$ du -sh /usr/local/mysql
1.3G    /usr/local/mysql

$ sudo useradd mysql
$ cd /usr/local/mysql
$ sudo bin/mysqld --initialize-insecure --user=mysql
2022-12-08T15:53:26.099038Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.31) initializing of server in progress as process 84746
2022-12-08T15:53:26.116373Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-12-08T15:53:26.510757Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-12-08T15:53:28.637373Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

$ sudo bin/mysqld --user=mysql --daemonize
mysqld will log errors to /usr/local/mysql/data/160-251-102-248.err
mysqld is running as pid 84809

起動もOK。

$ bin/mysql -uroot --skip-binary-as-hex

mysql> SELECT CURDATE();
+------------+
| CURDATE()  |
+------------+
| 2022-12-09 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT 0x436F6E6F486120416476656E742043616C656E6465722032303232;
+----------------------------------------------------------+
| 0x436F6E6F486120416476656E742043616C656E6465722032303232 |
+----------------------------------------------------------+
| ConoHa Advent Calender 2022                              |
+----------------------------------------------------------+
1 row in set (0.00 sec)


毎年、仕事で使っている以外の新しいCentOSに触れる唯一の機会になっているなあ。

良いお年を。

​

2022/12/07

MySQL闇歴史2 MySQLの製品版にRENAME DATABASEはあったことがない

この記事は MySQL闇歴史のカレンダー | Advent Calendar 2022 - Qiita の2枚目の7日目の記事です。

知名度:★★☆☆☆
闇度 :★☆☆☆☆
日本語ドキュメントは参考程度に度:★★★★☆


TL;DR

  • 5~6年以上前にDBAやサポートをやっている人は「 RENAME DATABASE でできません?」みたいなことを言われたことはないでしょうか。
    • あるいは、「 RENAME DATABASE がSyntax Errorで動きません、とか」
  • そのステートメントはMySQL 5.1.7(beta以前)に実装され5.1.27(Release Candidate)でリバートされた変更で、製品版に搭載されたことは一度もありません

RENAME DATABASE のもともとの記載はこんな。

何故これが「日本でだけ」(だと思う)一定数知られていたかというと、5.1の日本語マニュアルにがっつり載っていたから。

どう見てもGeneral Availavility(GA, 製品版)前に 撤回されたとは思えない 記述になっているのがミソ。
しかしこの5.1日本語ドキュメントの先頭をよく見てほしい。

- https://downloads.mysql.com/docs/refman-5.1-ja.a4.pdf

何のことはない、単にこのドキュメントは5.1.15-betaまでしか翻訳されておらず、以降ほっぽらかされているのである。なので、5.1.7~5.1.27(繰り返しますがGA前のRelease Candidate)で削除されたこのステートメントを知っている人が一定数いた。

MySQL 5.6の日本語ドキュメントがGoogle検索から5.1を駆逐したあたりまで、これが使えないか聞かれることはごく稀にあった。

今も5.6と8.0は日本語版が(英語以外で唯一)提供されているが、参照する時は「対応しているバージョン」を確認して、参考程度に原文にもあたってほしいと思います。


ちなみに2022/12/6現在、MySQL 5.6日本語版は5.6.23まで、MySQL 8.0日本語版は8.0.29までのカバーです。ゆめ忘れるな。

- https://dev.mysql.com/doc/refman/5.6/ja/manual-info.html

- https://dev.mysql.com/doc/refman/8.0/ja/preface.html

​

2022/10/10

MySQLは実はWindowsのdatadirをそのままLinuxに持って行っても動く(8.0では一ひねり必要)

タイトルがすべて。

MySQL 5.7.39をWindowsでinitializeして起動。

PS > bin\mysqld --initialize-insecure
mysqld: Could not create or access the registry key needed for the MySQL application
to log to the Windows EventLog. Run the application with sufficient
privileges once to create the key, add the key manually, or turn off
logging for that application.

PS > bin\mysqld --console
mysqld: Could not create or access the registry key needed for the MySQL application
to log to the Windows EventLog. Run the application with sufficient
privileges once to create the key, add the key manually, or turn off
logging for that application.
2022-10-10T05:54:48.343808Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-10-10T05:54:48.343866Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2022-10-10T05:54:48.344166Z 0 [ERROR] Cannot open Windows EventLog; check privileges, or start server with --log_syslog=0
2022-10-10T05:54:48.344184Z 0 [Note] C:\Users\yoku0\Downloads\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin\mysqld.exe (mysqld 5.7.39) starting as process 10508 ...
<snip>
2022-10-10T05:54:48.538979Z 0 [Note] C:\Users\yoku0\Downloads\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin\mysqld.exe: ready for connections.
Version: '5.7.39'  socket: ''  port: 3306  MySQL Community Server (GPL)

MySQL on Windows状態でテーブルにINSERT。

PS > bin\mysql -uroot

mysql> CREATE DATABASE d1;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE TABLE d1.t1 (num serial, val varchar(32));
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO d1.t1 VALUES (1, 'Initialized on Windows');
Query OK, 1 row affected (0.02 sec)

mysql> SELECT * FROM d1.t1;
+-----+------------------------+
| num | val                    |
+-----+------------------------+
|   1 | Initialized on Windows |
+-----+------------------------+
1 row in set (0.00 sec)

mysql> SHUTDOWN;
Query OK, 0 rows affected (0.00 sec)

mysqld.exeをシャットダウンして、datadirをLinuxホストにコピー。
Linux(今回はCentOS 7.9だった)側でそのdatadirを指定して起動。

$ scp -r data conoha:/tmp/5739

$ /usr/mysql/5.7.39/bin/mysqld --no-defaults --datadir=/tmp/5739
2022-10-10T05:59:35.702961Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2022-10-10T05:59:35.703117Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2022-10-10T05:59:35.877316Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-10-10T05:59:35.877370Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2022-10-10T05:59:35.877425Z 0 [Note] /usr/mysql/5.7.39/bin/mysqld (mysqld 5.7.39) starting as process 17330 ...
<snip>
2022-10-10T05:59:36.077227Z 0 [Note] Event Scheduler: Loaded 0 events
2022-10-10T05:59:36.077608Z 0 [Note] /usr/mysql/5.7.39/bin/mysqld: ready for connections.
Version: '5.7.39'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution

$ /usr/mysql/5.7.39/bin/mysql -uroot

mysql> SELECT * FROM d1.t1;
+-----+------------------------+
| num | val                    |
+-----+------------------------+
|   1 | Initialized on Windows |
+-----+------------------------+
1 row in set (0.01 sec)

フツーに浮くし、フツーにSELECTできた。
(ただし、8.0で禁止された動作のように途中で lower_case_table_names が変わってるのでテーブル名の大文字小文字を迂闊に変えるとハマる可能性はある)

同じく8.0。

PS > bin\mysqld --initialize-insecure

PS > bin\mysqld --console
2022-10-10T06:01:51.655936Z 0 [System] [MY-010116] [Server] C:\Users\yoku0\Downloads\mysql-8.0.30-winx64\mysql-8.0.30-winx64\bin\mysqld.exe (mysqld 8.0.30) starting as process 7024
2022-10-10T06:01:51.668243Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-10T06:01:51.944691Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-10-10T06:01:52.288537Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-10-10T06:01:52.288941Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-10-10T06:01:52.318492Z 0 [System] [MY-010931] [Server] C:\Users\yoku0\Downloads\mysql-8.0.30-winx64\mysql-8.0.30-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.30'  socket: ''  port: 3306  MySQL Community Server - GPL.
2022-10-10T06:01:52.318498Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060

PS > bin\mysql -uroot

mysql> CREATE DATABASE d1;
Query OK, 1 row affected (0.01 sec)

mysql> CREATE TABLE d1.t1 (num serial, val varchar(32));
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO d1.t1 VALUES (1, '8.0.30 Init on Windows');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM d1.t1;
+-----+------------------------+
| num | val                    |
+-----+------------------------+
|   1 | 8.0.30 Init on Windows |
+-----+------------------------+
1 row in set (0.00 sec)

mysql> SHUTDOWN;
Query OK, 0 rows affected (0.00 sec)

8.0.30はさっきと同じように—no-defaultsでdatadirを食わせるだけだと上がらない。

$ scp -r data conoha:/tmp/8030

$ /usr/mysql/8.0.30/bin/mysqld --no-defaults --datadir=/tmp/8030
2022-10-10T06:06:10.864755Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2022-10-10T06:06:10.864766Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
2022-10-10T06:06:11.113624Z 0 [System] [MY-010116] [Server] /usr/mysql/8.0.30/bin/mysqld (mysqld 8.0.30) starting as process 17699
2022-10-10T06:06:11.139472Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-10T06:06:11.437327Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-10-10T06:06:11.468902Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('0') and data dictionary ('1').
2022-10-10T06:06:11.469136Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-10-10T06:06:11.469160Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-10-10T06:06:11.999160Z 0 [System] [MY-010910] [Server] /usr/mysql/8.0.30/bin/mysqld: Shutdown complete (mysqld 8.0.30)  Source distribution.

8.0からは lower_case_table_names が

It is prohibited to start the server with a lower_case_table_names setting that is different from the setting used when the server was initialized.

で、MySQL on Windowsのデフォルトは lower_case_table_names=1 , MySQL on Linuxのデフォルトは lower_case_table_names=0 なのでエラる。

initializeした時と同じ値に合わせてやれば良いので(ただしもちろんLinuxなのにテーブル名の大文字小文字を区別しなくなるという弊害(?)は起こる。俺はどんな環境でも lower_case_table_names=1 推奨派なので全く困らないけれども)

$ /usr/mysql/8.0.30/bin/mysqld --no-defaults --datadir=/tmp/8030 --lower_case_table_names=1
2022-10-10T06:10:29.738697Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2022-10-10T06:10:29.738719Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
2022-10-10T06:10:29.986666Z 0 [System] [MY-010116] [Server] /usr/mysql/8.0.30/bin/mysqld (mysqld 8.0.30) starting as process 17785
2022-10-10T06:10:29.997767Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-10T06:10:30.222849Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: File '.\binlog.000001' not found (OS errno 2 - No such file or directory)
2022-10-10T06:10:30.520954Z 0 [ERROR] [MY-010958] [Server] Could not open log file.
2022-10-10T06:10:30.520977Z 0 [ERROR] [MY-010041] [Server] Can't init tc log
2022-10-10T06:10:30.520987Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-10-10T06:10:32.001836Z 0 [System] [MY-010910] [Server] /usr/mysql/8.0.30/bin/mysqld: Shutdown complete (mysqld 8.0.30)  Source distribution.

今度はバイナリログが見つからないらしい。
これの正体は binlog.index ファイルにWindowsファイルパス形式でバイナリログの在り処を記録しているからで

$ cat /tmp/8030/binlog.index
.\binlog.000001

binlog.index ごとバイナリログを全部消しちゃうか、 binlog.index を書き換えて ./ でLinuxファイルパス形式に書き換えてやれば良い。

$ vim /tmp/8030/binlog.index

$ cat /tmp/8030/binlog.index
./binlog.000001

三度目の正直で起動した。

$ /usr/mysql/8.0.30/bin/mysqld --no-defaults --datadir=/tmp/8030 --lower_case_table_names=1
2022-10-10T06:30:23.396869Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2022-10-10T06:30:23.396885Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
2022-10-10T06:30:23.649027Z 0 [System] [MY-010116] [Server] /usr/mysql/8.0.30/bin/mysqld (mysqld 8.0.30) starting as process 18175
2022-10-10T06:30:23.660111Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-10T06:30:23.910902Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-10-10T06:30:24.223477Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-10-10T06:30:24.223575Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-10-10T06:30:24.225695Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/tmp/8030' in the path is accessible to all OS users. Consider choosing a different directory.
2022-10-10T06:30:24.254458Z 0 [System] [MY-010931] [Server] /usr/mysql/8.0.30/bin/mysqld: ready for connections. Version: '8.0.30'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution.
2022-10-10T06:30:24.254470Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock

$ /usr/mysql/8.0.30/bin/mysql -uroot

mysql> SELECT * FROM d1.t1;
+-----+------------------------+
| num | val                    |
+-----+------------------------+
|   1 | 8.0.30 Init on Windows |
+-----+------------------------+
1 row in set (0.01 sec)

逆も似たようなもんだと思うけれど、俺にはWindowsとLinuxを跨いでdatadirの移動はやったこともないしやる予定もないと思う。

​