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.



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

Answer / Sonu Kumar Mishra

Here's a simple example of how you might approach this problem in C++ using the MySQL Connector/C++ library. Note that this example assumes you have the necessary libraries and headers installed.nn```cppnn#include <mysqllib.h>nnint main() {n MYSQL mysql; MySQL variable to hold database connection
mysql_init(&mysql); Initialize the MySQL object
n /* Connect to server */n if (!mysql_real_connect(&mysql, "localhost", "user", "password", "database", 0, NULL, 0)) {n fprintf(stderr, "Error connecting to database: %s
", mysql_error(&mysql)); Print error message and exit
return 1;n }nn /* Check if InnoDB plugin is installed */n MYSQL_RES *res = mysql_store_result(mysql); Store the result of the query
MYSQL_ROW row = mysql_fetch_row(res); Fetch a row from the result
n if (strcmp(row[0], "InnoDB")) {n fprintf(stderr, "InnoDB plug-in not installed
"); Print error message and exit
return 1;n }nn /* Query for total number of disk writes */n mysql_free_result(res); Free the previous result
MYSQL_QUERY query = mysql_query(&mysql, "SHOW GLOBAL STATUS LIKE 'Innodb_disk_writes'"); Query database
res = mysql_store_result(mysql); Store the result of the query
row = mysql_fetch_row(res); Fetch a row from the result
n if (row != NULL) {n int diskWrites = atoi(row[0]); Convert string to integer and store in diskWrites variable
printf("Total number of disk writes: %d
", diskWrites); Print the total number of disk writes
}n mysql_free_result(res); Free the result of the query
n mysql_close(&mysql); Close the MySQL connection
return 0;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More STL Interview Questions

wap in c++ which accept a integer array and its size as argument and replaces element having even values with its half and element having odd values with twice its value

1 Answers  


what is a template?

2 Answers   Amazon, BITS, IBS, Wipro,


5. Write c++ function that would intake a string and return the number of occurrences of a given character in that sring Ex:- if the word is “Colombo” and count the occurrences of the letter “o” the function would return 3

1 Answers  


How do I convert a stl file?

1 Answers  


what is an algorithm in terms of STL?

1 Answers   Lucent, Wipro,


what is template and type convertion

1 Answers   TATA,


What is stl language?

1 Answers  


What is Constructor

14 Answers   Angel Broking,


What is meant by stl in c++?

1 Answers  


tell about sorted linked list

1 Answers  


Is string part of stl?

1 Answers  


How is stl different from c++ standard library?

1 Answers  


Categories