-1

I would like to create an application that runs on a PC and connects to the mysql mariadb on my raspberry pi. I already managed to set it up on MySQL workbench, with the SSH connection options. However, I'd like to know how I can connect my app to that database.

Let's say my SSH is the default: username: pi password: raspberry

and for my database: host: localhost username: root password: Admin123

(these aren't the real logins, don't worry ;), but I don't feel like sharing the real information )

What would the code look like?

I'm familiar with

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("mydb");
db.setUserName("root");
db.setPassword("Admin123");
bool ok = db.open();

1 Answers1

1

127.0.0.1 is the loopback adapter IP address. It is always the IP address of the own host but not a remote address. So, if you are sure that the 10.0.3.36 is the IP address of the RPI, then you will be happy with that.

You should also make sure that MySQL port (likely to be 3306) is not firewalled on your RPI and the MySQL server accepts remote host connections for the user you are trying to connect with.

This tutorial may help you as well.

Soheil Armin
  • 2,725
  • 1
  • 6
  • 18