티스토리 뷰

https://github.com/clucle/cpp_mysql_vs2019

 

clucle/cpp_mysql_vs2019

mysql-connector with visualstudio. Contribute to clucle/cpp_mysql_vs2019 development by creating an account on GitHub.

github.com

 

1. Download MySQL & make database

download MySQL

https://dev.mysql.com/downloads/installer/

 

Install Server, Workbench, for Visua Studio (maybe optional Router)
Complete Install
Make Accounts

 

After installation, Open Workbench. Connect Mysql.

 

Execture query "CREATE DATABASE databasename" (Execute : Click thunder icon)
Execture query "SHOW DATABASES" & check your database exists

2. Download MySQL Connector8.0

download MySQL Connector cpp (current version 8.0 2020.01.20)

https://dev.mysql.com/downloads/connector/cpp/

 

Download zip file. Decompression zip file.

3. Download Boost & Install

(current version 1.72)

https://www.boost.org/doc/libs/1_72_0/more/getting_started/windows.html

You need to install as well as download (stage folder build by b2)

4. Set Environment variables

Set BOOST_ROOT & MYSQL_ROOT

5. Visual Studio Settings

Set C/C++ Generic (Additional Include Directory)
Set Linker Generic (Additional Library Directory)
Set Linker Input (Additional Dependency)

6. Copy Dll File

Copy & Paste 4 files.

Copy dll files
Open Porject Direcory

 

Result

7. Run Code

#include <stdlib.h>
#include <iostream>

#include <jdbc/cppconn/driver.h>
#include <jdbc/cppconn/exception.h>
#include <jdbc/cppconn/resultset.h>
#include <jdbc/cppconn/statement.h>

using namespace std;

int main(void)
{
	sql::Driver* driver;
	sql::Connection* con;

	driver = get_driver_instance();
	con = driver->connect("tcp://127.0.0.1:3306", "your_id", "your_password");
	con->setSchema("sampledatabase");

	delete con;

	cout << endl;

	return EXIT_SUCCESS;
}
댓글