C++ mysql8.0连接CLion
其中include和lib的目录都是connector安装路径拷贝过来的,而mysql目录是从mysql8.0安装路径拷贝过来,libmysql.dll和libmysql.lib从mysql安装路径的lib文件夹拷贝过来。mysql-connector版本:8.0.33。CMAKELIST.txt文件配置。环境变量配置(不知道影不影响)mysql版本:8.0.36。编译通过,连接成功则显示。CLi
·
mysql版本:8.0.36
mysql-connector版本:8.0.33
下载链接:
https://dev.mysql.com/downloads/
CLion的目录列表
其中include和lib的目录都是connector安装路径拷贝过来的,而mysql目录是从mysql8.0安装路径拷贝过来,libmysql.dll和libmysql.lib从mysql安装路径的lib文件夹拷贝过来。
环境变量配置(不知道影不影响)
系统变量-PATH
CMAKELIST.txt文件配置
cmake_minimum_required(VERSION 3.15)
project(innoDB_test)
set(CMAKE_CXX_STANDARD 14)
set(MYSQL_CONNECTOR_CPP_INCLUDE_DIR "C:/Program Files/mysql-connector-c++-8.0.33-winx64/include")
set(MYSQL_CONNECTOR_CPP_LIB_DIR "C:/Program Files/mysql-connector-c++-8.0.33-winx64/lib64/vs14")
include_directories(${MYSQL_CONNECTOR_CPP_INCLUDE_DIR})
include_directories(include)
include_directories(include/jdbc)
include_directories(mysql)
include_directories(mysql/include)
link_directories(lib)
link_libraries(libmysql)
add_executable(innoDB_test main.cpp)
target_link_libraries(innoDB_test libmysql)
C++代码测试
#include <windows.h>
#include <winsock.h>
#include <mysql.h>
#include <iostream>
int main() {
MYSQL mysql;
mysql_init(&mysql);
const char *unix = NULL;
if (mysql_real_connect(&mysql, "localhost", "root", "123456", "my_database", 3306, unix, 0)) {
std::cout << "success" << std::endl;
} else {
std::cout << "failed" << std::endl;
}
}
编译通过,连接成功则显示
更多推荐
已为社区贡献1条内容
所有评论(0)