简体   繁体   English

MySQL和Qt远程连接

[英]MySQL and Qt remote connection

I am trying to develop a simple program that connects into a mysql server. 我正在尝试开发一个连接到mysql服务器的简单程序。 Qt help is really helpfully in how to do it, but the problem in my case is that the program does not connect into a local server or a straight ip. Qt帮助确实对如何实现很有帮助,但是在我的情况下,问题是该程序未连接到本地服务器或纯IP。 My university provides a system for testing databases. 我的大学提供了一个测试数据库的系统。 So I have to connect first to the server, provide a password and after that connect to mysql with a different one. 因此,我必须首先连接到服务器,提供一个密码,然后再使用另一个密码连接到mysql。 The problem is that i do not know how mysql works and in qt i have found out how to connect straight to the server. 问题是我不知道mysql如何工作,在qt中我已经找到了如何直接连接到服务器。 I do not know if this problem has a simple solution but i couldn't find anything helpful. 我不知道这个问题是否有简单的解决方案,但是我找不到任何帮助。 Any help appreciated! 任何帮助表示赞赏!

int main(){    
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("195.*.*.*");
    db.setPort(22);
    db.setUserName("de0338");
    db.setPassword("pass");
    db.setDatabaseName("de0338");
    bool ok = db.open();
    if(!db.open())
    {       
        qFatal("Failed to Connect");  
    }
    return ok;
}

Try ising an ssh tunnel and then connect through this to Mysql. 尝试建立一个ssh隧道,然后通过它连接到Mysql。 Managing the ssh with Qt will be difficult. 用Qt管理ssh将很困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM