MySQL 8 has changed its default authentication plugin from mysql_native_password to caching_sha2_password to improve its security. However many third party libraries seem act slowly to catch up with this change. This causes some compatible issues with their connection to MySQL. One of the issues is seen in Go libraries while it's trying to connect to MySQL 8.
The specific error has been observed is "this authentication plugin is not supported". The root cause of this issue is that the go-sql-driver didn't support the new default authentication plugin. This bug has been reported a couple of months ago and it has been fixed in the latest release(1.4.0). The best advice to be given is to upgrade the go-sql-driver to 1.4.0 or above. See the release note for 1.4.0.
Major Release
- Multi-Results support
- context.Context support
- ColumnType support
- caching_sha2_password (MySQL 8 default) and sha256_password authentication support
- Transaction isolation level support
- Read-Only transactions support
- Many, many bugfixes
If for some reason the driver cannot be upgraded, there is a workaround can be applied which is to change the default authentication plugin back to mysql_native_password in mysql server configuration.
The location of the my.cnf can be found with below command
mysql --help | grep "Default options" -A 1
The output will list the candidate locations of the my.cnf file. After locating the my.cnf file, you can update the [mysqld] section and add one line like below:
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default-authentication-plugin=mysql_native_password
Thereafter restart the mysqld service and you should be able to connect to MySQL 8 as usual. However, we still advise you to upgrade your driver to the latest one if possible.
didn't work