Write a C/C++ program that connects to a MySQL server and
checks intrusion attempts every 5 minutes. If an intrusion
attempt is detected beep the internal speaker to alert the
administrator. A high number of aborted connects to MySQL at
a point in time may be used as a basis of an intrusion.



Write a C/C++ program that connects to a MySQL server and checks intrusion attempts every 5 minutes..

Answer / ruth

/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>

main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;

char *server = "localhost";
char *user = "root";
char *password = "PASSWORD"; /* set me first */
char *database = "mysql";

conn = mysql_init(NULL);

/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}

/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}

res = mysql_use_result(conn);

/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);

/* close connection */
mysql_free_result(res);
mysql_close(conn);
}

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Interview Questions

Is it possible to run a c program without using main?If yes HOW??

13 Answers   Wipro,


All technical questions

0 Answers   TCS,


what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

0 Answers   Wipro,


How we can insert comments in a c program?

0 Answers  


Can you explain what keyboard debouncing is, and where and why we us it? please give some examples

0 Answers   CSC, Wipro,






a C prog to swap 2 no.s without using variables just an array?

5 Answers   TCS,


Why clrscr is used after variable declaration?

0 Answers  


What is meant by int fun const(int a, int b) { .... ... }

1 Answers  


What is getch c?

0 Answers  


Explain what are linked list?

0 Answers  


hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?

0 Answers   HCL,


what is level of tree if leaf node is at level 4.please explain.

1 Answers   Wipro,


Categories