- Create a MySQL object:
mysql_init(NULL);
- Establish a connection to the MySQL server running at the specified host. Also, connect to the desired database:
mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)
- Create an execute SQL statement, comprised of show tables:
mysql_query(conn, "show tables")
- Save the result of the executing SQL query (that is, the table information of the mysql database) into a resultset:
res = mysql_use_result(conn);
- Fetch one row at a time from the resultset in a while loop and display only the table name from that row:
while ((row = mysql_fetch_row(res)) != NULL) printf("%s \n", row[0]);
- Free up the memory that is allocated to the resultset:
mysql_free_result(res);