When I was developing my own project, I needed to use MySQL for unit testing, so I started a MySQL container locally using docker, imitating the way of go-txdb. When I executed the test, the following error occurred.
Conclusion: The local client version is too low and does not support the server-side version of the authentication method.
mysql Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) using EditLine wrapper
- macOS 10.14.6 Mojave
- version: 8.0.25
- runtime environment: docker container
MySQL has used
caching_sha2_password as the authentication method by default since version 8.0, and 5.7 does not support this authentication method (5.7 uses
mysql_native_password by default).
Solution 1: Upgrade the client version
This is relatively simple, so I won’t explain it here.
Option 2: Set up the old
First log in to the container shell via the command line.
docker exec -it mysql /bin/bash # mysql is the name of your container, mine is mysql
Use the mysql command inside the container to connect to the server.
mysql -uroot # You may need other connection parameters, mine doesn't have a password
Modify the authentication method of the root account.
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '';