go连接MySQL报错:this authentication plugin is not supported的解决

MySQL升级8.0以上版本后,在用第三方库github.com/Go-SQL-Driver/MySQL打开数据库时会报错this authentication plugin is not supported,这是因为MySQL8.0版本修改了加密方式,所以只要修改一下密码的加密方式就可以了。

首先用root用户进入MySQL,修改root用户的密码和加密方式:这里修改密码为abc345

mysql> alter user root@localhost identified with mysql_native_password by 'abc345';
Query OK, 0 rows affected (0.13 sec)

mysql> 

查询当前所有用户:

mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| 127.0.0.1 | Tom              | caching_sha2_password |
| localhost | Tom              | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)

mysql> 

这里总共查询出来6个用户,刚才修改的是第6个,也就是最后一个用户| localhost | root | mysql_native_password |的密码和加密方式。可以看到,该用户的加密方式mysql_native_password已经不同于上面的其他5个加密方式了。

再修改其他用户:

mysql> alter user Tom@127.0.0.1 identified with mysql_native_password by '456789';
Query OK, 0 rows affected (0.03 sec)

mysql> 

查看:

mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| 127.0.0.1 | Tom              | mysql_native_password |
| localhost | Tom              | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)

mysql> 

之后重启MySQL,再次连接就可以了。

你可能感兴趣的:(数据库)