Syafiqlim / ESP32_MySQL

Optimized library for ESP32 to directly connect and execute SQL to MySQL database from ESP32 without intermediary
MIT License
6 stars 0 forks source link

Connection to bdd #1

Open playmiel opened 2 weeks ago

playmiel commented 2 weeks ago

Hi I wanted to try to use your library but I had some problems with the connection to the database, with the logs I could see that:

Client does not support authentication protocol requested by server; consider upgrading MySQL client.
Connection failed.

I wanted to know what protocol you use for the connection thanks

Syafiqlim commented 2 weeks ago

It uses SHA-1 for authentication to MySQL server. You must use MySQL native password instead of caching password. Also make sure the credentials and DB port is correct to your MySQL server. May I know the detail? Your .ino code and MySQL server version

playmiel commented 2 weeks ago

I'm using mysql-server 8.0 and here's some of my code:

 String mac = connexionState.mac;
    String CALL_SQL = "CALL assign_port_and_subdomain('" + String(mac) + "')";
    ESP32_MySQL_Connection conn((Client *)&client);
    if (conn.connectNonBlocking(server, server_port, user, password, default_database) != RESULT_FAIL)
    {
        Serial.println("Connected to database");

        // Create une requete pour recuperer les informations via un call
        ESP32_MySQL_Query query_mem = ESP32_MySQL_Query(&conn);
        if (!query_mem.execute(CALL_SQL.c_str()))
        {
            ESP32_MYSQL_DISPLAY("Insert error:");
            query_mem.show_results();

            return false;
        }
        else
        {
            ESP32_MYSQL_DISPLAY("Data Inserted.");
                        query_mem.show_results();
            // // Lire le résultat de la procédure
            // // Récupérer les colonnes de résultats
            // column_names *cols = query_mem.get_columns();
            // for (int f = 0; f < cols->num_fields; f++)
            // {
            //     Serial.print(cols->fields[f]->name);
            //     if (f < cols->num_fields - 1)
            //     {
            //         Serial.print(",");
            //     }
            // }
            Serial.println("\n--------------------");

            // Lire les lignes et les afficher
            // row_values *row = NULL;
            // do
            // {
            //     row = query_mem.get_next_row();
            //     if (row != NULL)
            //     {
            //         for (int f = 0; f < cols->num_fields; f++)
            //         {
            //             Serial.print(row->values[f]);
            //             if (f < cols->num_fields - 1)
            //             {
            //                 Serial.print(",");
            //             }
            //         }
            //         Serial.println();
            //     }
            // } while (row != NULL);
        }
        conn.close();
        return true;
    }

but I understood where the error came from by looking at the logs: [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead', is it possible to change the connection protocol directly with the library? If not, I could implement it if possible.