Accessing MySQL through C++ [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit t开发者_运维技巧he question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this questionI want to run queries on my MySQL server through a C++ program that will be released to the public for free, but not under the GPL or any other open-source license.
My first question is if I can use the MySQL Connector/C++ library in my application.
If not, then what alternatives are there for me to use?
Unfortunately, MySQL has changed client libraries licenses from LGPL to GPL which means that any application linking with those libraries statically or dynamically becomes a derivative work. Therefore, you cannot use MySQL client libraries (that are used to access MySQL server) in non-FOSS applications unless you purchase a license for that. A FOSS here stands for Free & Open Source. A list of FOSS licenses recognized by Oracle, the owner of MySQL, can be found here.
However, you can use ODBC to access MySQL without distributing any MySQL libraries etcetera, so client is responsible for that and have to decide whether to use Open Source or commercial MySQL license, which does not obligate you to purchase any licenses or distribute your software under FOSS license recognized by Oracle. Read this article for more details.
Another interesting part about GPL is that it states that application that links to a GPL library is a derivative work. It means that if you will make a minimalistic open source application that links to MySQL client libraries and communicates with MySQL server, defines an API interface and dynamically loads your commercial/closed-source library which will export only that defined API implementation, you will not violate license terms and conditions because in that case open source application will be a user of closed-source product. The same approach is used by commercial graphics drivers (like NVidia) and audio codecs (like MP3).
Dolphin Connector:
https://github.com/poetinha/dolphin-connector
The safest bet is probably to use the ODBC connector as Vlad suggested, but that's really just pushing the licensing headache down to your clients/users (ie: it's up to them to verify that the usage is correct with respect to the various licenses). In concept it might be fine for an application with any license to use an ODBC driver which is licensed under the GPL as long as it's not statically linked (that is, it's dynamically loaded based on a connection string), but one could argue that the user was then violating the GPL by causing the application to use the GPL component in violation of the usage license for the GPL component (since the application was not also available under the GPL). It can get messy, and it's not generally legally clear-cut: you may be safe, but your users may be in violation in any real-world usage scenario.
My advice would be to avoid anything GPL is you're not using it for your own app (and everything else you're using), and you can avoid it; there's a good reason why lots of people avoid GPL-ed software like the plague. If you're writing on Windows, just use SQL Server Express with the regular MDAC connectors: they are both free, readily available, performant, and place no particular restrictions or rights management on your code (unlike GPL libraries). For Linux, I don't know, but I'm sure there are alternatives.
Okay, you can use this: http://forge.mysql.com/wiki/Connector_C%2B%2B
But fair warning: it sucks. Just read the MySQL connector forums, it's pretty amusing how awful this connector is.
Or you can use this: http://tangentsoft.net/mysql++/
It's much better, but still kind of sucks.
My personal experience with MySQL and C++ has been a nightmare. I'm currently re-writing a dispatch server in Java because I just can't handle the memory leaks, malloc
crashes, segfaults, etc, etc. I could have went the C route and just used the C connector (which is quite stable, I hear), but I'm not writing stuff in an object oriented language to have to use C libraries.
As far as the license is concerned, you're out of luck. You have to get a license to sell your commercial application if it uses a MySQL connector (C or C++).
You could, however, use an MIT (or equivalent) ODBC API which (I think) should allow you to release/sell commercial and closed-source software that has MySQL capability (through a driver, not native).
精彩评论