As the old ancient C Programmers MySQL client writing

Daibel Inle Martínes Sánchez
4 min readNov 6, 2020

Connecting a C program to MySQL/MariaDB server

Today I waked up with the idea to get a simple and ancient school project rebuilding, step by step to help others who won in mistakenly steps over connecting a simple C program to a MySql locally/remote running database.It’s not too hard but in deep little details mistakenly may give you very bad headaches.

Software and requirements:

You may use what ever c/cpp MingGW IDE (Integrated Development Environment ) you want but my old one preferred has been Code Blocks and the Lib-MySQLv5.05–1sid.devpack from bloodshed Dev C++ project.

Code-blocks and Lib-MySQL

1- Download and install Codeblocks from the official website.

2- Download the Lib-MySQL

Devpacks are 7ziped files and you can unpack them and
take lib files -> CodeBlocks/MinGW/lib
header files -> CodeBlocks/MinGW/include

Which we are doing right now on these steps:

Finished this preparation steps, now we may start configuring the build options to include the MySQL library.

By default Code-Blocks create a first testing code which just print “hello world” … Now we Run and Build this to make sure there is no problems with the installation process and the created project.

Once we are sure that its clean and ready to start we setup the libraries inclusion before start coding.

Now the next are very important steps…

Now, here we have to be very carefully.. :

First, we have to select “My Computer”. Then select by default the hard-drive where we installed previously code-blocks [By default is in -> C:\ ] then navigate to the CodeBlocks MinGW libraries [files with .a extension] installation folder, in my case it is located at these path [C:\Software\CodeBlocks\MinGW\lib] and select the required library “libmysql.a” as shown blow.

!!You will get a final Alert,DON'T ACCEPT THE DEFAULT OPTION asking to keep as relative path, YOU MUST click it as NO.

Now we have to make the same action with the includes folder.First select search directories, click on Add, click on three dots to browse and select includes folder, then click on Ok, and be sure that the Add directory menu has the right path to the includes folder.Then click on Ok, and again time look carefully the Alert message…

The alert message again time is by default asking to keep it as relative path… Click on “No!!”.

And Continue to Ok to save the previous selected path.

Now we are able to start coding with no problems….

The code is executed is built and ran successfully.At these point you may modify it to make CRUD operations [Create/Read/Update/Delete] as you need on your projects.

This first and easy overview is hosted on github.

// Thanks and I hope be helpfully to you with this post.

--

--

Daibel Inle Martínes Sánchez

Computer Sciences Bachelor, Freelance, Software Developer, allways forever learner, foreign languages and Sciences lover