GA

2026/08/25

ALTER TABLEがMetadata Lockで詰まらされた時に検知する何か

TL;DR

  • yt-mdl-checker というスクリプトを書いた
  • performance_schema.metadata_locks から PENDING になっている EXCLUSIVE なロックを引いて、同じテーブルで既に GRANTED になっているやつを KILL するスクリプト
  • クエリ自体は大したことないので、わざわざスクリプト使わなくてもスニペットとして使えるはず

主に「 ALTER TABLE 流したらオンラインALTER TABLEのはずなのに刺さった」対策。たとえ SELECT でも、一度でもそのテーブルに触って COMMIT されていないトランザクションがあれば、その共有MDLが ALTER TABLE の排他MDLをブロックしてしまって、その後のクエリが共有MDLを取れなくなって連鎖的にやられていくケース。

ALTER TABLE 開始時の排他MDLに刺さったらCtrl+Cすればいいだけだけど、オンラインALTER TABLEは一度共有MDLにフォールバックした後 ALTER TABLE 終了処理の中でもう一度排他MDLを取ろうとするので、後者を止めるのは難しい(ずっと張り付いてられるくらいの時間なら張り付いていればいいだけだけれども)ので、なんかALTER TABLEとセットで流せる奴があるといいなとか思った。

使い方は mysql コマンドラインクライアントと似たようなオプションで

$ yt-mdl-checker -hlocalhost -uroot -p'xxx' -i 3 --kill

とかやっておけば、3秒おきにチェックして勝手に KILL してくれそうな感じにしてある。
READMEも書いてます。

https://github.com/yoku0825/ytkit/blob/9b4af50b98b6a16b8f44f084d7220e32a4290c63/README.md#L571-L662

2026/06/26

Group ReplicationでのExecuted_Gtid_Setの進み方

TL;DR

  • たとえシングルプライマリモードだろうと、GTIDは「そのマシンが使うレンジ」が先に割り当てられて、その中からGTIDを払い出していく
  • 元プライマリが使っていたGTIDレンジは、割り当てられたレンジが使い切られない限り、再びプライマリに戻った時に再利用する。

yt-sandbox ってやつでグループレプリケーション環境のコンテナが簡単に立ち上げられるらしいよ(ステマ)

$ yt-sandbox -t gr 8.4
[2816233] NOTE: Generate Sandbox directry into /home/yoku0825/yt-sandbox/golf
[2816233] NOTE: Node1 Container Ipaddress: 172.17.0.2
[2816233] NOTE: Node2 Container Ipaddress: 172.17.0.3
[2816233] NOTE: Node3 Container Ipaddress: 172.17.0.4
Sandbox deployed into /home/yoku0825/yt-sandbox/golf

$ cd /home/yoku0825/yt-sandbox/golf

$ ll
total 28
-rwxr-xr-x. 1 yoku0825 yoku0825 485 Jun 26 08:26 check_group_replication
-rw-r--r--. 1 yoku0825 yoku0825  97 Jun 26 08:26 destroy_all
-rw-r--r--. 1 yoku0825 yoku0825  54 Jun 26 08:26 hosts
lrwxrwxrwx. 1 yoku0825 yoku0825  40 Jun 26 08:26 m -> /home/yoku0825/yt-sandbox/golf/node1/use
drwxr-xr-x. 3 yoku0825 yoku0825 101 Jun 26 08:26 node1
drwxr-xr-x. 3 yoku0825 yoku0825 101 Jun 26 08:26 node2
drwxr-xr-x. 3 yoku0825 yoku0825 101 Jun 26 08:26 node3
-rwxr-xr-x. 1 yoku0825 yoku0825  97 Jun 26 08:26 restart_all
lrwxrwxrwx. 1 yoku0825 yoku0825  40 Jun 26 08:26 s1 -> /home/yoku0825/yt-sandbox/golf/node2/use
lrwxrwxrwx. 1 yoku0825 yoku0825  40 Jun 26 08:26 s2 -> /home/yoku0825/yt-sandbox/golf/node3/use
-rwxr-xr-x. 1 yoku0825 yoku0825  95 Jun 26 08:26 start_all
-rwxr-xr-x. 1 yoku0825 yoku0825  94 Jun 26 08:26 stop_all
-rwxr-xr-x. 1 yoku0825 yoku0825  93 Jun 26 08:26 use_all

シングルプライマリーで上がってくるので、1号機に接続して操作。

$ ./m
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 8.4.9 MySQL Community Server - GPL

Copyright (c) 2000, 2026, Oracle and/or its affiliates.

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.

golf-1> SHOW BINARY LOG STATUS;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000001 |      158 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

golf-1> create database d1;
Query OK, 1 row affected (0.01 sec)

golf-1> create table d1.t1 (num serial, val varchar(32));
Query OK, 0 rows affected (0.02 sec)

golf-1> INSERT INTO d1.t1 VALUES (1, 'one');
Query OK, 1 row affected (0.00 sec)

golf-1>
golf-1>
golf-1> SHOW BINARY LOG STATUS;
+---------------+----------+--------------+------------------+------------------------------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                        |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000001 |      848 |              |                  | 01234567-89ab-cdef-0123-456789abcdef:1-3 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)

golf-1> ^DBye

2号機をプライマリーにして書き込み。
100万番単位でGTIDが割り振られるっぽく、100万飛んで1のGTIDが振られる。

【2026/06/26 18:31】
レンジの大きさは group_replication_gtid_assignment_block_size デフォルト100万で決められる。
$ ./s1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 8.4.9 MySQL Community Server - GPL

Copyright (c) 2000, 2026, Oracle and/or its affiliates.

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.

golf-2> SELECT group_replication_set_as_primary(@@server_uuid);
+------------------------------------------------------------------+
| group_replication_set_as_primary(@@server_uuid)                  |
+------------------------------------------------------------------+
| Primary server switched to: b91f989d-7138-11f1-aa86-0242ac110003 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)

golf-2>
golf-2> SHOW BINARY LOG STATUS;
+---------------+----------+--------------+------------------+------------------------------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                        |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000001 |      845 |              |                  | 01234567-89ab-cdef-0123-456789abcdef:1-3 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)

golf-2>
golf-2> INSERT INTO d1.t1 VALUES (3, 'three');
Query OK, 1 row affected (0.00 sec)

golf-2>
golf-2> SELECT * FROM d1.t1;
+-----+-------+
| num | val   |
+-----+-------+
|   1 | one   |
|   3 | three |
+-----+-------+
2 rows in set (0.01 sec)

golf-2>
golf-2> SHOW BINARY LOG STATUS;
+---------------+----------+--------------+------------------+--------------------------------------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                |
+---------------+----------+--------------+------------------+--------------------------------------------------+
| binlog.000001 |     1137 |              |                  | 01234567-89ab-cdef-0123-456789abcdef:1-3:1000001 |
+---------------+----------+--------------+------------------+--------------------------------------------------+
1 row in set (0.00 sec)

1号機にプライマリーを戻して書くと、3の次の4が使い回される。

$ ./m
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 8.4.9 MySQL Community Server - GPL

Copyright (c) 2000, 2026, Oracle and/or its affiliates.

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.

golf-1> SELECT group_replication_set_as_primary(@@server_uuid);
+------------------------------------------------------------------+
| group_replication_set_as_primary(@@server_uuid)                  |
+------------------------------------------------------------------+
| Primary server switched to: b24cf04e-7138-11f1-b6c3-0242ac110002 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)

golf-1>
golf-1> SHOW BINARY LOG STATUS;
+---------------+----------+--------------+------------------+--------------------------------------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                |
+---------------+----------+--------------+------------------+--------------------------------------------------+
| binlog.000001 |     1137 |              |                  | 01234567-89ab-cdef-0123-456789abcdef:1-3:1000001 |
+---------------+----------+--------------+------------------+--------------------------------------------------+
1 row in set (0.00 sec)

golf-1>
golf-1> INSERT INTO d1.t1 VALUES (4, 'four');
Query OK, 1 row affected (0.00 sec)

golf-1>
golf-1> SHOW BINARY LOG STATUS;
+---------------+----------+--------------+------------------+--------------------------------------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                |
+---------------+----------+--------------+------------------+--------------------------------------------------+
| binlog.000001 |     1428 |              |                  | 01234567-89ab-cdef-0123-456789abcdef:1-4:1000001 |
+---------------+----------+--------------+------------------+--------------------------------------------------+
1 row in set (0.00 sec)

マルチプライマリなら疑問に思うこともないくらい自然な動作だし、シングルプライマリーでも super_read_only 外したら書けちゃうくらいなので、そのへんの動作は一緒なのであろう。

2026/05/07

MySQL Shellのフルバックアップとmysqlbinlogを合わせてPITR

MySQL ShellのdumpInstanceとMySQL ShellのdumpBinlogs ではなく MySQL ShellのdumpInstanceとmysqlbinlogの組み合わせでのPITR

テスト用コンテナの起動とテスト用のデータ作成とハートビートの書き込み。GTIDは有効な状態。

$ yt-sandbox 8.0
[3254174] NOTE: Generate Sandbox directry into /home/yoku0825/yt-sandbox/bravo
[3254174] NOTE: Node1 Container Ipaddress: 172.17.0.2
Sandbox deployed into /home/yoku0825/yt-sandbox/bravo

$ cd /home/yoku0825/yt-sandbox/bravo
$ ./n1 -e "CREATE DATABASE sbtest"

$ sysbench --mysql-host=172.17.0.2 --mysql-user=root oltp_read_write prepare --table-size=100000 --tables=10
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)

Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 100000 records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 100000 records into 'sbtest3'
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest4'
Creating a secondary index on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest5'
Creating a secondary index on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 100000 records into 'sbtest6'
Creating a secondary index on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest7'
Creating a secondary index on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest8'
Creating a secondary index on 'sbtest8'...
Creating table 'sbtest9'...
Inserting 100000 records into 'sbtest9'
Creating a secondary index on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 100000 records into 'sbtest10'
Creating a secondary index on 'sbtest10'...

$ yt-heartbeat -h 172.17.0.2 -uroot -v

まずはMySQL Shellの util.dumpInstance でフルバックアップを取る。

$ date ; mysqlsh mysql://root@172.17.0.2 --js -- util dumpInstance '/tmp/test' ; date
Thu May  7 07:43:06 GMT 2026
Please provide the password for 'root@172.17.0.2':
Save password for 'root@172.17.0.2'? [Y]es/[N]o/Ne[v]er (default No):
Acquiring global read lock
Global read lock acquired

..
Uncompressed data size: 191.90 MB
Compressed data size: 87.48 MB
Compression ratio: 2.2
Rows written: 1000092
Bytes written: 87.48 MB
Average uncompressed throughput: 191.90 MB/s
Average compressed throughput: 87.48 MB/s
Thu May  7 07:43:10 GMT 2026

dumpInstanceは論理バックアップなので、 START TRANSACTION WITH CONSISTENT SNAPSHOT を使っている。よって、このバックアップをリストアした時に復旧できるタイムスライスは「バックアップを開始した時刻」になる。これはバックアップ先の @.json に入っていそう。

$ jq -r .begin /tmp/test/@.json
2026-05-07 07:43:09

もう1個サンドボックスを立ち上げてリストアしてみる。 updateGtidSet=replace にしないと新しいGTIDを払い出しちゃうので指定する。

$ yt-sandbox 8.0
[3255163] NOTE: Generate Sandbox directry into /home/yoku0825/yt-sandbox/charlie
[3255163] NOTE: Node1 Container Ipaddress: 172.17.0.3
Sandbox deployed into /home/yoku0825/yt-sandbox/charlie

$ cd /home/yoku0825/yt-sandbox/charlie
$ ./n1 -e "SET GLOBAL local_infile = ON"

$ date ; mysqlsh mysql://root@172.17.0.3 --js -- util loadDump '/tmp/test' { --updateGtidSet=replace } ; date
Thu May  7 07:49:37 GMT 2026
Please provide the password for 'root@172.17.0.3':
Save password for 'root@172.17.0.3'? [Y]es/[N]o/Ne[v]er (default No):
Loading DDL and Data from '/tmp/test' using 4 threads.

..
Resetting GTID_PURGED to dumped gtid set
11 chunks (1.00M rows, 191.90 MB) for 11 tables in 2 schemas were loaded in 23 sec (avg throughput 8.16 MB/s, 42.54K rows/s)
13 DDL files were executed in 0 sec.
Data load duration: 23 sec
Total duration: 23 sec
0 warnings were reported during the load.

Thu May  7 07:50:04 GMT 2026

$ ./n1 -e "SELECT hostname, server_time FROM ytkit.heartbeat ORDER BY server_time DESC LIMIT 1"  -- 07:43:09.546 のデータが手に入った
+----------+-------------------------+

| hostname | server_time             |
+----------+-------------------------+
| bravo-1  | 2026-05-07 07:43:09.546 |
+----------+-------------------------+

↑うーん、ミリ秒まで @.json に入っていてほしい気もする…。

あとはmysqldumpの時と同じく、「リストア後のGTIDが歯抜けにならないように」(= この場合は「少なくとも必ず b55fb915-49e7-11f1-87a5-0242ac110002:495 とそれ以降のGTID」を含む)バイナリログを適用すればいい。

rsyncか何かで定期的にバイナリログを他の場所に移しておいて(cpで代用)

$ mkdir work
$ sudo cp -ip /home/yoku0825/yt-sandbox/bravo/node1/datadir/binlog.00000* work/
$ ll work/
total 186720
-rw-r-----. 1 mysql mysql       180 May  7 07:38 binlog.000001
-rw-r-----. 1 mysql mysql       180 May  7 07:38 binlog.000002
-rw-r-----. 1 mysql mysql 191192963 May  7 07:54 binlog.000003

mysqlbinlogの —stop-datetime で着地したい時間を指定しつつ mysql コマンドラインクライアントに食わせる。

GTIDモードなので二重適用を恐れる必要はなく、邪魔にならない程度(無視されるとはいえ、GTIDをチェックして空振りさせるので多少の時間は必要で、ぴったり495から始める自信があるなら495から始めても良い)にgtid_executedがオーバーラップするように適用させる。

↑の例だと俺なら binlog.000001 から適用してしまう。000001と000002は実質空っぽだし、000003の07:43:09.546以前のイベントは単に読み捨てられるので。

$ sudo mysqlbinlog --stop-datetime="2026-05-07 07:50:03" work/* | mysql -h172.17.0.3 -uroot

$ ./n1 -e "SELECT hostname, server_time FROM ytkit.heartbeat ORDER BY server_time DESC LIMIT 1"
+----------+-------------------------+
| hostname | server_time             |
+----------+-------------------------+
| bravo-1  | 2026-05-07 07:50:02.848 |
+----------+-------------------------+

$ ./n1 -e "SHOW MASTER STATUS"
+---------------+-----------+--------------+------------------+---------------------------------------------------------------------------------------+
| File          | Position  | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                     |
+---------------+-----------+--------------+------------------+---------------------------------------------------------------------------------------+
| binlog.000001 | 190977368 |              |                  | b55fb915-49e7-11f1-87a5-0242ac110002:1-904,
ecc7abed-49e8-11f1-ad40-0242ac110003:1-24 |
+---------------+-----------+--------------+------------------+---------------------------------------------------------------------------------------+

mysqlbinlogの --stop-datetime は当該時刻「以上」のタイムスタンプ(秒まで)が現れた時点でbreakするので、7:50:03.855860のgitd=’b55fb915-49e7-11f1-87a5-0242ac110002:905’ は適用されない。

$ sudo mysqlbinlog -vv work/binlog.000003 | less
..
# at 191101220
#260507  7:50:03 server id 201  end_log_pos 191101299 CRC32 0xaa35a563  GTID    last_committed=904      sequence_number=905     rbr_only=yes    original_committed_timestamp=1778140204080496   immediate_commit_timestamp=1778140204080496     transaction_length=362
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
# original_commit_timestamp=1778140204080496 (2026-05-07 07:50:04.080496 GMT)
# immediate_commit_timestamp=1778140204080496 (2026-05-07 07:50:04.080496 GMT)
/*!80001 SET @@session.original_commit_timestamp=1778140204080496*//*!*/;
/*!80014 SET @@session.original_server_version=80046*//*!*/;
/*!80014 SET @@session.immediate_server_version=80046*//*!*/;
SET @@SESSION.GTID_NEXT= 'b55fb915-49e7-11f1-87a5-0242ac110002:905'/*!*/;
# at 191101299
#260507  7:50:03 server id 201  end_log_pos 191101382 CRC32 0x768811b1  Query   thread_id=13    exec_time=0     error_code=0
SET TIMESTAMP=1778140203.855860/*!*/;
BEGIN
/*!*/;
# at 191101382
#260507  7:50:03 server id 201  end_log_pos 191101448 CRC32 0x2ce58d7d  Table_map: `ytkit`.`heartbeat` mapped to number 145
# has_generated_invisible_primary_key=0
# at 191101448
#260507  7:50:03 server id 201  end_log_pos 191101551 CRC32 0xde01d932  Write_rows: table id 145 flags: STMT_END_F

BINLOG '
K0T8aRPJAAAAQgAAAAj6YwsAAJEAAAAAAAEABXl0a2l0AAloZWFydGJlYXQABA8SEvwF/AMDAwIA
AgP8/wB9jeUs
K0T8aR7JAAAAZwAAAG/6YwsAAJEAAAAAAAEAAgAE/wAHAGJyYXZvLTGZuc58gyFwmbnOfIMhZioA
YjU1ZmI5MTUtNDllNy0xMWYxLTg3YTUtMDI0MmFjMTEwMDAyOjEtOTA0MtkB3g==
'/*!*/;
### INSERT INTO `ytkit`.`heartbeat`
### SET
###   @1='bravo-1' /* VARSTRING(1020) meta=1020 nullable=0 is_null=0 */
###   @2='2026-05-07 07:50:03.856' /* DATETIME(3) meta=3 nullable=0 is_null=0 */
###   @3='2026-05-07 07:50:03.855' /* DATETIME(3) meta=3 nullable=0 is_null=0 */
###   @4='b55fb915-49e7-11f1-87a5-0242ac110002:1-904' /* BLOB/TEXT meta=2 nullable=0 is_null=0 */
# at 191101551
#260507  7:50:03 server id 201  end_log_pos 191101582 CRC32 0xaa63b7d5  Xid = 16673
COMMIT/*!*/;

..

とこんな感じ。


【2026/05/08 16:28】

この手順と直接関係はないけど、updateGtidSet=replaceなのにgtid_executedに2台ぶんのGTIDが入ってしまっているのでバグレポートした

MySQL Bugs: #120418: unexpected Executed_Gtid_Set after util.loadDump with updateGtidSet: replace

https://bugs.mysql.com/bug.php?id=120418


2026/04/30

MySQL 5.7とそれ以前のpartial_revokesもどき

TL;DR

  • さっさとMySQL 8.0とそれ以降にアップグレードして partial_revokes を使う
  • 過去にはこんなテクニックがあったんだよという記憶だけ

日々の覚書: GRANTでデータベース名にワイルドカードを指定することとpartial revokesと でもちょっと書いていた、「GRANTでデータベース名にワイルドカード」を一捻りしたバージョン。

「一般ユーザーに(データベース名は動的に変わる、などの理由で)任意のスキーマに対するCREATE, DROPその他の権限を割り当てたいけど mysqlperformance_schemasys だけはダメ、グローバルGRANTはやりたくない」という、まさに partial_revokes が欲しい状況を5.7で何とかしたい。

mysql (とその他システム) スキーマには明示的な *_priv = 'N' を割り当てて、それ以外の % にはスキーマレベルでのALLをGRANTする。

mysql57 8> SELECT @@version;
+------------+
| @@version  |
+------------+
| 5.7.44-log |
+------------+
1 row in set (0.00 sec)

mysql57 8> CREATE USER yoku0825;
Query OK, 0 rows affected (0.00 sec)

mysql57 8> GRANT ALL ON `%`.* TO yoku0825 WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql57 8> INSERT INTO mysql.db (host, db, user) VALUES ('%', 'mysql', 'yoku0825'), ('%', 'sys', 'yoku0825'), ('%', 'performance_schema', 'yoku0825');   -- *_privカラムのデフォルトは 'N'
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql57 8> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

「明示的な *_priv = 'N' の割り当て」はGRANTステートメントではできない ( GRANT USAGE ON mysql.* TO yoku0825 とかやっても mysql.db に全部 ‘N’ の行ができたりはしない)っぽいので、INSERTステートメントとFLUSH PRIVILEGESで表現する。

と、

mysql57 9> SHOW GRANTS;  -- 自分がmysqlスキーマとかに権限がないことが見えないのが嫌だといえば嫌だが (partial_revokesは見える)
+-------------------------------------------------------------------+
| Grants for yoku0825@%                                             |
+-------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'yoku0825'@'%'                              |
| GRANT ALL PRIVILEGES ON `%`.* TO 'yoku0825'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql57 9> SELECT COUNT(*) FROM mysql.user;
ERROR 1142 (42000): SELECT command denied to user 'yoku0825'@'localhost' for table 'user'

mysql57 9> SHOW TABLES FROM sys;
ERROR 1044 (42000): Access denied for user 'yoku0825'@'%' to database 'sys'

mysql57 9> CREATE DATABASE yoku0825;
Query OK, 1 row affected (0.00 sec)

mysql57 9> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| d1                 |
| world              |
| yoku0825           |
+--------------------+
4 rows in set (0.00 sec)

だいたいやりたいことができそう。
partial_revokesを有効にするとスキーマ名ワイルドカードが効かなくなるからできなくなるけど、そもそもつなぎのためのテクニックだろうからそれはそれで(アップグレードする時に忘れずに処置すれば)大丈夫なはず。


【2026/05/07 18:04】

「この場合、yoku0825アカウントでCREATE USER yoku0826してGRANT ALL ON `%`.* TO yoku0826するとyoku0826アカウントはmysqlスキーマ読めますね?」

「じゃあ INSERT INTO mysql.db (host, db, user) VALUES ('%', 'mysql', ''), ('%', 'sys', ''), ('%', 'performance_schema', '') にすれば空文字がユーザー名におけるワイルドカード扱いなのでそれで防ごう」