# MySql 接入记录：VS 配置踩坑纪实

> 发布时间: 2026-08-02 18:25

# MySql 接入记录踩坑纪实

## 导入流程

1. 从 mysql 官网下载最新的 mysql-connector，分为 Release 和 Debug，需要分别下载，否则对应的模式编译会报错

![Alt text](https://file.sub.opengm.top/p/public/image.png)

2. 配置包含头文件及静态库（未尝试动态库）

![Alt text](https://file.sub.opengm.top/p/public/image-1.png)
![Alt text](https://file.sub.opengm.top/p/public/image-2.png)
![Alt text](https://file.sub.opengm.top/p/public/image-3.png)

3. 将 c++ 标准升级为 c++17

此为多余的一步，同时导致了 byte 无法识别的问题
解决方法：在 C/C++ 命令行中加入 `/D_HAS_STD_BYTE=0` 命令

![Alt text](https://file.sub.opengm.top/p/public/image-4.png)

4. 此时仍然会有 Link 报错

原因：vs 编译 mysql 库时需要添加预编译宏来告知编译器是使用静态库（STATIC_CONCPP）还是动态库（DSTATIC_CONCPP）
解决方法：在 C/C++/预处理器/预处理器中添加对应的宏

![Alt text](https://file.sub.opengm.top/p/public/image-5.png)
![Alt text](https://file.sub.opengm.top/p/public/image-6.png)
![Alt text](https://file.sub.opengm.top/p/public/image-7.png)

5. 至此 mysql 可以运行，但是连接时报错

```
CDK Error: unexpected message
```

这是由于 mysqlcppconn8 的默认端口为 33060 而不是 3306 导致的，修改端口后顺利运行