C++ and Mysql connection


C++ and Mysql database


This section is crucial for those who are new to C++ and Mysql database connection and data manipulation in Windows OS. This short tutorial will guide you step by step to connect to Mysql database using C or C++ programming language. It also teaches you how to manipulate the database after you successfully connect it by code.


1. Download and Install Mysql server 5.5
Before, you can use C or C++ code to connect to Mysql databases, you must download and install Mysql server (e.g Mysql Server 5.5). You may use search engines (e.g. www.google.com) to look for the source of Mysql server file. This source is distributed in both zip file and msi file. My recommendation is to use msi file because it is easy to install.You only click the file and follow the instructions. Then you will get Mysql server installed on your hard drive.
After you successfully install Mysql server 5.5 on your computer running Windows OS, you will find the following path:
C:/Program Files/MySQL/MySQL Server 5.5
 
2. Create C or C++ project and add library files to the Dev-C++ project option
 
Although you have installed Mysql server successfully and you also have Dev-C++ editor, you still cannot connect to Mysql server databases. It is important that you add library files—libmysql.lib and libmysql.a to the linker box in parameters tab of your current working project (I suppose you can create project in Dev-C++ editor) as shown below:

c++ add mysql database library

 
You will find the two important library files in lib folder of your Dev-C++ editor (e.g. C:/Dev-Cpp/lib).



Comments

Phan Neth, CICI, year 3 comment

 Phan Neth, CICI, year 3

Now it is ok teacher. I can connect to database and select data from it. Than you so much teacher !!!!!


2013-04-30
Dara comment

 Dara

Copy and paste the link below to the address box to learn how to connect C and Mysql server:
http://www.worldbestlearningcenter.com/index_files/cpp-tutorial-connect_mysql_database.htm


2013-04-27
Phan Neth, CICI, year 3 comment

 Phan Neth, CICI, year 3

Hello teacher i want to connect C programming language to MySql server but it have problem. When i compile it always error with library " my_global.h
and mysql.h", so how should i do?


2013-04-27



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.