Linux系統下C/C++開發MySQL資料庫應用

來源:互聯網
上載者:User

一、Linux下掛載光碟機:

掛載光碟機 mount -t iso9660 /dev/cdrom /mnt/cdrom

卸載光碟機 umount /dev/cdrom

彈出光碟機 eject

推進光碟機 eject –t

二、運行MySQL只需安裝:

mysql-server-3.23.54a-11.i386.rpm

mysql-3.23.54a-11.i386.rpm

開發MySQL需要特別安裝開發包:

mysql-devel-3.23.54a-11.i386.rpm


三、Linux程式包的安裝:

rpm –ivh 要安裝的軟體包

rpm –qa | grep 特定的軟體包

rpm –e 要刪除的軟體包


四、Linux中Mysql服務的啟動:

/etc/rc.d/init.d/mysqld status 查看當前的mysql服務狀態

service mysqld start 啟動mysql服務

mysql –u root –p pass 使用使用者名稱root和密碼pass串連mysql資料庫


五、Linux C/C++開發MySQL程式結構

標頭檔:#include

編譯選項:

gcc -o server server.c –I /usr/include/mysql –L /usr/lib/mysql –l mysqlclient –lz –lm

串連過程:

Step 1:串連資料庫

建立MYSQL mysql;

mysql_init(&mysql);初始化

mysql_real_connect(&mysql,”hostname”,”username”,”password”,”database”,0,NULL,0);

Step 2:執行SQL語句

mysql_real_query(&mysql,SQL);

Step 3:擷取查詢結果

建立MYSQL_RES結構 *res;

res = mysql_store_result(&mysql);

Step 4:擷取查詢結果每一行,並進行相應處理

mysql_fetch_row(res);

mysql_num_fields(res); 擷取結果的欄位數

printf(“%s\n”,row[index]);

Step 5:釋放資源

mysql_free_result(res);

mysql_close(&mysql); 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.