新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
安裝MySQL數(shù)據(jù)庫(kù)中獲得MySQL.h建立C接口的操作流程
此文章主要向大家描述的是安裝MySQL數(shù)據(jù)庫(kù)中獲得 MySQL.h 建立C接口的實(shí)際操作流程,首先我們是從安裝MySQL數(shù)據(jù)庫(kù)開(kāi)始的,其中涉及相關(guān)的實(shí)際應(yīng)用代碼的描述,下面就是文章的具體內(nèi)容描述。

先安裝MySQL
代碼:
- sudo apt-get install MySQL-server MySQL-client
再裝開(kāi)發(fā)包
代碼:
- sudo apt-get install libMySQLclient15-dev
安裝MySQL數(shù)據(jù)庫(kù)完以后,C代碼里添加頭文件
代碼:
- #include < mysql .h>
編譯方法:
代碼:
- gcc $(mysql_config --cflags) xxx.c -o xxx $(mysql_config --libs)
可以用以下代碼測(cè)試一下
代碼:
- /* Simple C program that connects to MySQL Database server*/
- #include
- #include
- main() {
- MYSQL *conn;
- MYSQL_RES *res;
- MYSQL_ROW row;
- char *server = "localhost";
- char *user = "root";
- char *password = "";
此處改成你的密碼
- 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);
- }
會(huì)輸出現(xiàn)有數(shù)據(jù)庫(kù)和表內(nèi)容。以上的相關(guān)內(nèi)容就是對(duì)安裝MySQL數(shù)據(jù)庫(kù)獲得 MySQL.h 建立C接口的介紹,望你能有所收獲。
【編輯推薦】
- MySQL 群集的概念與ndb群集構(gòu)架圖
- C#開(kāi)發(fā)MySQL中文亂碼的妙招
- MySQL 事件調(diào)度器示例演示
- 實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)備份,很簡(jiǎn)單!
- MySQL匹配模式的實(shí)現(xiàn)方案簡(jiǎn)介
網(wǎng)頁(yè)名稱:安裝MySQL數(shù)據(jù)庫(kù)中獲得MySQL.h建立C接口的操作流程
本文URL:http://m.fisionsoft.com.cn/article/cdhipop.html


咨詢
建站咨詢
