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.

Answer Posted / raghavendra

/* 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 ?    17 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

1741


the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

2090


Why does everyone say not to use scanf? What should I use instead?

1104


How do I swap bytes?

853


a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2583


How do I convert a string to all upper or lower case?

890


How is a pointer variable declared?

812


What does 3 periods mean in texting?

839


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

871


What is context in c?

751


Explain how can you tell whether two strings are the same?

829


Do you know pointer in c?

831


How can you invoke another program from within a C program?

844


What are the preprocessor categories?

850


Is c dynamically typed?

910