自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

安裝MySQL數據庫中獲得 MySQL.h 建立C接口的操作流程

數據庫 MySQL
今天主要向大家描述的是安裝MySQL數據庫中獲得 MySQL.h 建立C接口的實際操作步驟,下面就是文章的主要內容描述,望你會有所收獲。

此文章主要向大家描述的是安裝MySQL數據庫中獲得 MySQL.h 建立C接口的實際操作流程,首先我們是從安裝MySQL數據庫開始的,其中涉及相關的實際應用代碼的描述,下面就是文章的具體內容描述。

先安裝MySQL

代碼:

  1. sudo apt-get install MySQL-server MySQL-client 

再裝開發(fā)包

代碼:

  1. sudo apt-get install libMySQLclient15-dev 

安裝MySQL數據庫完以后,C代碼里添加頭文件

代碼:

  1. #include <mysql.h> 

編譯方法:

代碼:

  1. gcc $(mysql_config --cflags) xxx.c -o xxx $(mysql_config --libs) 

可以用以下代碼測試一下

代碼:

  1. /* Simple C program that connects to MySQL Database server*/  
  2. #include <mysql.h> 
  3. #include <stdio.h> 
  4. main() {  
  5. MYSQL *conn;  
  6. MYSQL_RES *res;  
  7. MYSQL_ROW row;  
  8. char *server = "localhost";  
  9. char *user = "root";  
  10. char *password = "";   

此處改成你的密碼

  1. char *database = "mysql";  
  2. conn = mysql_init(NULL);  
  3. /* Connect to database */  
  4. if (!mysql_real_connect(conn, server,  
  5. user, password, database, 0, NULL, 0)) {  
  6. fprintf(stderr, "%s\n", mysql_error(conn));  
  7. exit(1);  
  8. }  
  9. /* send SQL query */  
  10. if (mysql_query(conn, "show tables")) {  
  11. fprintf(stderr, "%s\n", mysql_error(conn));  
  12. exit(1);  
  13. }  
  14. res = mysql_use_result(conn);  
  15. /* output table name */  
  16. printf("MySQL Tables in mysql database:\n");  
  17. while ((row = mysql_fetch_row(res)) != NULL)  
  18. printf("%s \n", row[0]);  
  19. /* close connection */  
  20. mysql_free_result(res);  
  21. mysql_close(conn);  
  22. }  

 

會輸出現(xiàn)有數據庫和表內容。以上的相關內容就是對安裝MySQL數據庫獲得 MySQL.h 建立C接口的介紹,望你能有所收獲。

【編輯推薦】

  1. MySQL 群集的概念與ndb群集構架圖
  2. C#開發(fā)MySQL中文亂碼的妙招
  3. MySQL 事件調度器示例演示
  4. 實現(xiàn)MySQL數據庫備份,很簡單!
  5. MySQL匹配模式的實現(xiàn)方案簡介

     
責任編輯:佚名 來源: cnblogs
相關推薦

2010-05-20 17:56:43

2010-05-28 18:44:45

2010-05-26 11:21:00

MySQL數據庫操作

2010-05-25 09:47:05

2010-06-12 09:53:19

2011-03-03 10:00:14

ProFTPD建立MySQL

2010-05-12 18:02:11

MySQL數據庫

2010-06-12 17:48:45

MySQL數據庫表

2010-05-28 13:48:07

MySQL數據庫密碼

2019-10-21 08:08:34

MySQL數據庫主鍵

2011-07-05 18:04:45

QT Mysql

2010-06-01 09:32:09

MySQL數據庫

2010-05-11 13:50:56

MySQL數據庫

2010-06-04 18:45:00

MySQL數據庫

2010-05-24 14:02:06

MySQL數據庫

2010-06-01 13:58:24

遠程連接MySQL

2010-06-04 10:59:54

MySQL數據庫返回影

2010-06-10 08:48:14

2024-04-03 00:06:03

2009-02-03 13:06:17

日常維護規(guī)范MySQL
點贊
收藏

51CTO技術棧公眾號