0
0

More than 1 year has passed since last update.

ローカル環境からdockerのmysqlへ接続

Posted at
  1. コンテナを動かす
docker run \
--name mydb \
-itd \
--hostname my-mysql \
-e MYSQL_ROOT_PASSWORD=mypassword \
-e BIND-ADDRESS=0.0.0.0 \
-p 3305:3306 \
public.ecr.aws/docker/library/mysql:8.0

※portは3305に設定

2.mysqlへ接続、DB&ユーザー&権限作成

docker exec -it <コンテナ名> mysql -u <ユーザ名> -p

3.ローカルでmysqlにログイン

mysql -u <ユーザー名> -h 127.0.0.1 -p --port=3305

エラーがでてしまう

ERROR 1045 (28000): Plugin caching_sha2_password could not be loaded: 指定されたモジュールが見つかりません。 Library path is 'caching_sha2_password.dll'

ローカルのmysqlクライアントツールでcaching_sha2_password がサポートされていないため起こる。
4.認証方法の変更

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'new_root_password';
Query OK, 0 rows affected (0.01 sec)

再度接続してみたが、

Error 1045 (28000): Access denied for user ~~

5.userのホストを'localhost'から'%'に変更

RENAME USER 'ユーザー名'@'ホスト名' to '新ユーザー名'@'新ホスト名';

6.再度接続

mysql -u <ユーザー名> -h 127.0.0.1 -p --port=3305

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MySQL [(none)]>

接続完了!

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