日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql安装连接测试c_Ubuntu 12.04下安装mysql并用C程序测试连接

發布時間:2023/12/31 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql安装连接测试c_Ubuntu 12.04下安装mysql并用C程序测试连接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.先安裝mysql 代碼:sudo apt-get install mysql-server mysql-client 2.再裝開發包 代碼:sudo apt-get install libmysqlclient-dev

啟動mysql服務:

1.net start mysql 這是在DOS環境下采用的命令,在linux中沒有這個命令.

2.?/etc/init.d/mysql restart 這是linux下的服務啟動命令,我的機子上已經啟動本服務,運行命令的結果顯示如下

上面顯示已經開啟服務,還給出了相應進程號.

3.測試連接,編輯conn_mysql.c文件:

代碼:

#include

#include

#include

int main(int argc, char *argv[])

{

MYSQL my_connection;

int res;

mysql_init(&my_connection);

/*mysql_real_connect(&mysql,host,user,passwd,dbname,0,NULL,0) == NULL)*/

if (mysql_real_connect(&my_connection, "localhost", "root", "xtaywgqt","c_test",0,NULL,CLIENT_FOUND_ROWS))

{

printf("Connection success\n");

res = mysql_query(&my_connection, "insert into user_info values(3,'Li','f')");

if (!res)

{

printf("Inserted %lu rows\n",(unsigned long)mysql_affected_rows(&my_connection));

/*里頭的函數返回受表中影響的行數*/

}

else

{

//分別打印出錯誤代碼及詳細信息

fprintf(stderr, "Insert error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));

}

mysql_close(&my_connection);

}

else

{

fprintf(stderr, "Connection failed\n");

if (mysql_errno(&my_connection))

{

fprintf(stderr, "Connection error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));

}

}

return EXIT_SUCCESS;

}

4.編譯方法:

gcc $(mysql_config --cflags) conn_mysql.c -o conn_mysql $(mysql_config --libs)

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的mysql安装连接测试c_Ubuntu 12.04下安装mysql并用C程序测试连接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。