Write a C/C++ program that connects to a MySQL server and
checks if the InnoDB plug-in is installed on it. If so, your
program should print the total number of disk writes by MySQL.

Answers were Sorted based on User's Feedback



Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installe..

Answer / pramod badiger

/* C ++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL*/
#include <mysql.h> /*provides C client library to write programs for MySQL*/
#include <stdio.h> /*standard input/output header*/
#include<plugin.h> /* Is used with mysql storage engines like InnoDB plugin*/


int main()
{
MYSQL *conn; /* pointer to connection handler */
MYSQL_RES *res; /*Variable for storing db results*/
MYSQL_ROW row; /*variable for storing the single row of db*/

char *server_name = "localhost"; /* server host */
char *user_name = "root"; /* username (default=login name) */
char *password = "2ba07is045"; /* your login password*/
char *database_name = "mysql"; /*database name*/

conn = mysql_init(NULL); /* initialize connection handler */

/* CONNECTION TO MySQL SERVER */

if (mysql_real_connect(conn, server_name, user_name, password, database_name, 0, NULL,
0)==NULL)
{
/*Connection Failed*/
fprintf (stderr, "mysql_real_connect() failed\n");
/*close the connection*/
mysql_close (conn);
exit (1);

}
/*checking wheather InnoDB plug-in is installed or what */
if (mysql_query(conn, "select *from information_schema.plugins where
plugin_name=’mysql_plugin’ ")!==NULL) /*fuction returns zero if the statement was successful, Nonzero if an error occurred*/
{
printf(“InnoDB plug –in is not installed\n”);
exit(1);
}

/*After invoking mysql_query() or mysql_real_query(), we must call mysql_store_result() or mysql_use_result() for every statement that successfully produces a result set*/

res = mysql_use_result(conn);/* returns MYSQL_RES structure otherwise NULL if an error
occurred*/
printf("Information of installed InnoDB plug-in…………….\n");
/*Prints Plug-in type,name,author,version etc*/

while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
mysql_free_result(res);

/* send SQL query SHOW TABLES to list the non-TEMPORARY tables in a given database */

if (mysql_query(conn, "show tables")!=NULL)
/*returns zero if the statement was successful. Nonzero if an error occurred*/
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}

res = mysql_use_result(conn);/* returns MYSQL_RES structure otherwise NULL if an error
occurred*
/* Prints tables name in the database */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
mysql_free_result(res);

/*Number of Disk writes By the MySQL*/

if (mysql_query(conn, "SHOW STATUS LIKE 'key_writes%'"))
/*returns zero if the statement was successful. Nonzero if an error occurred*/
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}

res = mysql_use_result(conn); /*stores key writes*/
row = mysql_fetch_row(res); /*fetching the result*/
printf(“No of Disk writes\n”)
printf("%s ", row[0]); /*Displaying the No of Disk writes By MySQL*/

mysql_close(conn); /*close the connection*/
}

Is This Answer Correct ?    10 Yes 2 No

Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installe..

Answer / bhagya

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

Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installe..

Answer / raja bhar

#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 ?    4 Yes 0 No

Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installe..

Answer / susmita

Actually it is not answer.I have a question.how can we run the C program connecting to the MYSQL server?

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

0 Answers  


How do I use arrays in c++?

0 Answers  


Can you think of a situation where your program would crash without reaching the breakball, which you set at the beginning of main()?

1 Answers  


In what situations do you have to use initialization list rather than assignment in constructors?

0 Answers  


How do you traverse a btree in backward in-order?

0 Answers  






What is the use of string in c++?

0 Answers  


How do you define a class in c++?

0 Answers  


What is near, far and huge pointers? How many bytes are occupied by them?

0 Answers  


Write about the retrieval of n number of objects during the process of delete[]p?

0 Answers  


What are function prototypes?

0 Answers  


What is the difference between a definition and a declaration?

0 Answers  


What is the size of pointer ? Also size of pointer in 64 bit pointer

4 Answers  


Categories