Qt中使用mysql連線遠端伺服器

2021-07-24 08:27:03 字數 1884 閱讀 1623

1、首先檢視有沒有mysql的驅動。

一般qt開始時都沒有mysql這個驅動。顯示 mysql driver is not valid。這裡 我們只討論qt5.2.1版本的,如果是版本的話,可能會很麻煩。要去編譯mysql驅動。所以我建議還不如直接解除安裝了,用最近的呢。

qt5.2.1版本如何解決沒有mysql驅動這個問題呢?很簡單,如果你的電腦裡面沒有暗轉mysql資料庫,就去安裝個。安裝完mysql,可能要加環境變數。編輯path,在後面加上c:\program files\mysql\mysql server 5.7\bin 。

然後到安裝目錄,將c:\program file\mysql\mysql server 5.7\lib\中的libmysql.dll這個檔案拷貝到d:\qt\qt5.2.1\5.2.1\mingw48_32\bin 目錄下。ps:以上的目錄是我電腦的安裝目錄,具體要根據你自己的電腦。

mysql安裝好後,自己就可以直接用dos測一下了:

mysql -u 使用者名稱 -p密碼 -h 位址 例:mysql -u root -p123 -h 127.0.0.1

這裡可以介紹幾個mysql簡單的命令: show databases;//顯示資料庫  usemysql ;//選擇那個資料庫 show table ;//顯示表 describe 表名;//顯示某個表的字段說明

db.sethostname(sip);  

db.setport(iport);

db.setusername(susernm);

db.setpassword(spwd);

//連線sql伺服器

bool r = db.open();

if (r)

}

/*插入資料*/

qsqlquery query2 = qsqlquery(db);

qstring sq1 = qobject::tr("insert into sql_2000(id,ip,port,username,password,dbtype,dbname)"

"values (?, ?, ?, ?, ?, ?, ?)");

bool b = query2.prepare(sq1);

if(b)

query2.bindvalue(0, id+1);

query2.bindvalue(1, sip);

query2.bindvalue(2, iport);

query2.bindvalue(3, susernm);

query2.bindvalue(4, spwd);

query2.bindvalue(5, sdbtype);

query2.bindvalue(6, sdbnm);

/*查詢資料*/

qsqlquery query3 = qsqlquery(db);

query3.prepare("select * from sql_2000 where id=1");

bool c = query3.exec();

if (c)

}

else

/*刪除資料*/

qsqlquery query4 = qsqlquery(db);

query4.prepare("delete from sql_2000 where id=1");

bool d = query4.exec();

if (d)

else

}

else

db.close();

jupyter notebook連線遠端伺服器

本文對紅字部分的在伺服器上啟動jupyter notebook做了簡單修改作為自己的備忘 作者原文非常完美,閱讀請移步檢視完整版本 在遠端伺服器上,啟動jupyter notebooks服務 jupyter notebook no browser port 8889在本地終端中啟動ssh ssh n...

jupyter notebook連線遠端伺服器配置

需求 使用jupyter notebook 連線遠端伺服器 一 安裝並配置jupyter notebook pip install jupyter生成配置檔案 jupyter notebook generate config更改配置檔案 vim jupyter jupyter notebook co...

使用RStudio遠端連線MySQL

環境 遠端機 linux mysql 本地機 windows rstudio 問題 1.遠端機為內網機器,需要跳板機連線,沒有公網ip,無法連線 解決方案 修改跳板機的iptables,將內網機器映 到跳板機的a埠上 2.使用rmysql連線時出現host is not allowed to con...