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

  • Post author:
  • Post category:mysql


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,再次连接就可以了。



版权声明:本文为Charliewolf原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。