0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mysql_native_passwordのMySQLが欲しいときのdocker-compose

Posted at

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 |
+------------------+-----------+-----------------------+
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?