Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
How to connect and code a C Program with a MySQL database in Windows?

I have recently learned MySQL and I want to implement the knowledge on how to build a C Program using MySQL database on windows. Can anyone provide me with a detailed description on which files to download and whether I need XAMPP running or not?

I have tried to read the documentation here : https://dev.mysql.com/doc/refman/8.0/en/c-api-implementations.html . However , I couldn't figure out for my life how to do it on Windows.(Seems pretty easy for Linux, unfortunately I do not have a Linux machine)

It would be great if someone would provide me with a detailed and step by step explanation. Thanks in advance.

I know how the code would look like.

#include <stdio.h>
#include <stdlib.h>
#include <my_global.h>
#include <mysql.h>

typedef struct
{
    char host[20];
    char user[25];
    char pass[50];
}DB_CONN_PARAMS;

MYSQL * connect_db(DB_CONN_PARAMS *params)
{
    MYSQL *connection = mysql_init(NULL);//init connection
    if (connection == NULL)
    {//check init worked
        fprintf(stderr, "%s\n", mysql_error(connection));
        exit(EXIT_FAILURE):
    }
    //connect:
    if (mysql_real_connect(
            connection,
            params->host,
            params->user,
            params->pass,
            NULL,0,NULL,0)
        ==NULL)
    {//connection failed?
        fprintf(stderr, "%s\n", mysql_error(connection));
        mysql_close(connection);
        exit(EXIT_FAILURE):
    }
    return connection;
}

int main()
{
    MYSQL *db;
    DB_CONN_PARAMS *params = calloc(1,sizeof(DB_CONN_PARAMS));
    //just an alternative way of passing connection params, find a struct easier
    params->host = "127.0.0.1";
    params->user = "root";
    params->pass = "mySuperSecretPass";
    MYSQL * connect_db(DB_CONN_PARAMS *params);
    db = connect_db(params);
    //we don't need the struct anymore
    free(params);
    params = NULL;
    //do stuff
    mysql_close(db);//close connection, of course!
    return EXIT_SUCCESS;
}

I just need help with the setup.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!