实验环境:
vs2015
Windows10 64位
c++
问题
调用#include "mysql.h"连接数据库。
注:
连接的是本地的数据库localhost
报错信息:
Authentication plugin ‘caching_sha2_password’ cannot be loaded
定位报错:
mysql_real_connect()失败。
调用mysql_error()可以知道出错原因:Authentication plugin ‘caching_sha2_password’ cannot be loaded
发现是密码格式的问题,可以定位确实是数据库user的配置问题。
解决方案:
定位确实是数据库user的配置问题。
这是因为VS工程导入的mysql-connector-c-6.1.11-win32库不支持‘caching_sha2_password’,据说后来的8.x版本支持了,我还没有试过。
这个时候在host主机的数据库中新建一个user,不使用‘caching_sha2_password’插件,最好用命令行直接新建用户,不建议用客户端工具新建。
在mysql cmd中:
create user 'user'@