MySQL8.4からmysql_native_passwordがデフォルト無効になったらしい。
以下の小細工でmysql_native_password有効なMySQLが立ち上がる。
docker-compose.yml
docker-entrypoint-initdb.d/
001_setup.sql
docker-compose.yml
services:
mysql:
image: mysql:8.4.2
container_name: mysql
command: --mysql-native-password=ON
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: testdb
volumes:
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
docker-entrypoint-initdb.d/001_setup.sql
ALTER USER `root`@`%` IDENTIFIED WITH mysql_native_password BY 'password';
ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'password';
# docker compose up -d
// ここでdocker-entrypoint-initdb.d/が実行される時間がしばらくあるので待つ20秒くらい
# docker compose exec mysql mysql -ppassword -e "select user, host, plugin from mysql.user;"
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| root | % | mysql_native_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | mysql_native_password |
+------------------+-----------+-----------------------+