adspace


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.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

draw a flowchart that accepts two numbers and checks if the first is divisible by the second.

3480


sir please send me bpcl previous question papers

2481