0. Introduction
MySQL as a current mainstream open source relational database, has been widely concerned by everyone. Devc++ is also an open source, simple C + + editor that has a simpler and faster compilation than vs. But there are few links to MySQL connection devc++ on the Internet, most of which are MySQL link vs, or connection tutorials for Java,python. This article, which will compensate for this shortcoming, I spend a lot of time querying similar information from multiple websites and will be integrated. If there are some inappropriate places, please forgive the reader.
1. Preparatory work
When devc++ link data, we first need some preparation to ensure the subsequent operation.
1.devc++ Installation Mysql.devpak
Below provides my Baidu network disk share address, can download directly:
Links: Https://pan.baidu.com/s/1Y6q0emGEsaMU5GQZNLf3YQ
Password: 4lti
MySQL connecter/c++ website Address: https://dev.mysql.com/downloads/connector/cpp/1.1.html
After the installation is complete, the package Manager can be found in the Devc++ toolbar, i.e. the installation is complete.
2.MySQL of installation Preparation
Installation version varies from person to person, one of the following is available on the official website: https://dev.mysql.com/downloads/installer/
When the installation is complete, locate the following path
(I'm using MySQL5.7 here.)
2. Start operation1. associating Files
Project---project Properties--parameters, open the following
Enter-wall in the C compiler
Enter-W in the C + + compiler
Link, add a library or object, (Find devc++ installation directory/LIB/LIBMYSQL.A), add libmysql.a the library; Fill in such as-lmysql
As follows:
Project---project Properties--File/directory
Add separately: Library directory: (just MySQL directory)/lib
Include file directory: (just MySQL directory)/include
2. Here, the link is done almost, and then the C + + header file is introduced
#include <mysql.h>
You can do it.
MySQL connection database operation in 3.c++
1 #defineHOST "localhost"2 #defineUSER "Root"//(write your own user name here)3 #definePASSWORD "***************"//(Write your own database password here)4 #defineTABLE "Stock"//(write your own library name here, my library is the stock)5 #definePORT 33066 7Mysql_init (&mycont);//Initialize handle8Mysql_real_connect (&mycont,host,user,password,table,port,null,0);//Open Database9Mysql_set_character_set (&mycont,"GBK");//Set character formattingTenMysql_close (&mycont);//Close the database
4. End
Here, the chapter is over, if there is no place, you can contact the author Oh.
MySQL connection problem with devc++