简体   繁体   English

如何使用OTL ODBC驱动程序将C ++连接到MySQL?

[英]How to connect C++ to MySQL with OTL ODBC driver?

I'm having trouble connecting to my MySQL database using the OTL ODBC Driver on C++. 我在C ++上使用OTL ODBC驱动程序无法连接到MySQL数据库。 I'm using Visual Studio 2019, and the problem appears to be on the connection string. 我正在使用Visual Studio 2019,问题似乎出在连接字符串上。 My MySQL database is hosted on localhost with easyPHP, but I'll need to use an online database later, this first database is just for tests. 我的MySQL数据库使用easyPHP托管在localhost上,但是稍后我将需要使用在线数据库,第一个数据库仅用于测试。

I tried multiple types of connection strings, but I think I didn't fully get what should I supply as the DSN 我尝试了多种类型的连接字符串,但我认为我没有完全得到应提供的DSN

db.rlogon("root@127.0.0.1"); // connect to the database

I also tried 我也试过

db.rlogon("root/@mysql"); // connect to the database

and

db.rlogon("root","","127.0.0.1:3306",0); // connect to the database

I expected it to connect, but it didn't, and I got this error: 我希望它能够连接,但是没有,但是我得到了这个错误:

"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

I managed to do it, I asked the creator of the OTL library and he helped me what to do: 我设法做到了,我问过OTL库的创建者,他帮助我该怎么做:

In Windows 7, go to Control Panel > Administrative Tools > ODBC Data Sources (32-bit) or > ODBC Data Sources (64-bit) 在Windows 7中,转到控制面板>管理工具> ODBC数据源(32位)或> ODBC数据源(64位)

And then you can create an ODBC DSN there, and it's what you need to provide for the connection. 然后,您可以在此处创建ODBC DSN,这是您提供连接所需要的。

Alternatively, you can use a connection string (He recommended me this website: https://www.connectionstrings.com/ ) 或者,您可以使用连接字符串(他向我推荐了此网站: https : //www.connectionstrings.com/

Anyway, I got it to work 无论如何,我得到了它的工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM