When connecting to MySQL using ESP32, the monitoring window gets stuck at 'Trying'

Hello everyone! Recently, I've been trying to send data to MySQL using ESP32, but encountered an issue that I can't resolve (as shown in the attached image).
7dbf252f04ff2f7f8428f429921488d0a8242fe6_2_690x156

I'm using the Arduino IDE for coding. After completing the WiFi connection, attempting to connect to MySQL gets stuck. I've checked that the WiFi and MySQL credentials are correct (they're on the same local network), and the port is also open without any blocking. Strangely, MySQL shows attempted logins but they fail. It's somewhat like a connection timeout issue. I'd like to ask all the experts here if you know where the problem might be, or if anyone has encountered a similar situation before! :smiling_face_with_tear:

Below is the MySQL connection code.

#include <WiFi.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

const char* ssid = "";  //WIFI 名稱
const char* WIFI_password = "";  //WIFI 密碼

IPAddress server_addr( , , , ); // MySQL IP地址
unsigned int server_port = 3306;           // MySQLport
char user[] = "";                  // MySQL帳號
char password[] = "";              // MySQL密碼
char db[] = "";               // 數據庫

WiFiClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
  Serial.begin(115200);
  delay(100);
  
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, WIFI_password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  Serial.println("Connecting to database...");
  if (conn.connect(server_addr, server_port, user, password, db)) {
    Serial.println("Connected to database");
    
    MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
    char query[] = "SELECT * FROM your_table";
    cur_mem->execute(query);
    delete cur_mem;
  } else {
    Serial.println("Connection failed");
    Serial.println("Exiting program");
    while (true) {
      delay(1);
    }
  }
}

void loop() {
  delay(1000);
}

I think we also need to know if you're using the standard Arduino library or another one with the same name. Because I never tried but I'm not pretty sure it could work 100% with ESP32 boards.

MySQL logs should show you more information about those failed connections, if either is a timeout or other issue about login. Take a deeper look to understand in detail what happens.

Yes, I am using the MySQL_Connector_Arduino library. I have checked my MySQL logs but found no results. I should say I don't have any logs named MySQL.

Well, if you're using a MySQL server, you should know where you can find configuring details (in this case about logs...), don't you?

You could start from MySQL web site, I guess....:wink:
https://dev.mysql.com/doc/refman/8.3/en/server-logs.html