Trying to acess a MySql Database over Wifi with ESP8266

Hello,
i am trying to program an ESP8266 using Arduino IDE, my goal is the access a mysql database running on my main pc using xampp.

I came up with the following code:

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <ESP8266WiFi.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>   
#include <ArduinoJson.h>
#include <time.h>

// W-lan Anmeldedaten
const char* ssid = "(....)"; 
const char* password = "(....)";
byte mac[6];
WiFiServer server(80);
IPAddress ip(192, 168, 178, 33);
IPAddress gateway(192, 168, 178, 1);
IPAddress subnet(255, 255, 255, 0);

//Connection Daten für mysql datenbank
IPAddress server_addr(192,168,178,67);  // IP of the MySQL server here
char user[] = "myuser";              // MySQL user login username
char passwordDb[] = "mypassword";        // MySQL user login password
WiFiClient dbClient; 

MySQL_Connection conn((Client *)&dbClient);







//-----------------------------------------------------------------------------


void setup() {
Serial.begin(9600);

 configTime(0, 0, "pool.ntp.org");      // die UTC zeit vom NTP(Network Time Protocol)
  client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org

// mit dem W-Lan verbinden
WiFi.mode(WIFI_STA);
WiFi.config(ip,gateway,subnet);
WiFi.begin(ssid, password);



// Beim Verbinden Status ausgeben
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}

  
// Die Locale IP Adresse vom ESP ausgeben
Serial.println(WiFi.localIP());

WiFi.macAddress(mac);
server.begin();


while (conn.connect(server_addr, 3306, user, passwordDb) != true) {
    delay(200);
    Serial.print ( "." );
}

Serial.println("");
Serial.println("Connected to SQL Server!");      
}

This is followed by a loop statement of course which a left out to make my posting short.

But I receive the somewhat cryptic error message, when trying to connect to the mysql database:

23:08:43.670 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
23:08:43.717 -> 
23:08:43.717 -> Exception (28):
23:08:43.717 -> epc1=0x40206f00 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000049 depc=0x00000000
23:08:43.822 -> 
23:08:43.822 -> >>>stack>>>
23:08:43.822 -> 
23:08:43.822 -> ctx: cont
23:08:43.857 -> sp: 3ffffc20 end: 3fffffc0 offset: 0190
23:08:43.904 -> 3ffffdb0:  000008ed 3fffc6fc 126037d0 00000000  
23:08:43.949 -> 3ffffdc0:  00f81c03 00000001 00000001 40206f53  
23:08:43.994 -> 3ffffdd0:  40230000 00000000 3ffe8630 40206f40  
23:08:44.087 -> 3ffffde0:  3fff3030 3fff018c 3fff2f30 4020fcd8  
23:08:44.087 -> 3ffffdf0:  fffffffc 3fffc200 00000022 40240bfc  
23:08:44.182 -> 3ffffe00:  00000014 3fff2f2c 000000ff 3ffef770  
23:08:44.182 -> 3ffffe10:  4020fca4 3ffe8630 3ffefb90 4020a990  
23:08:44.277 -> 3ffffe20:  3fff2fec 3ffefb90 00000000 4020a9b4  
23:08:44.323 -> 3ffffe30:  3fff2fec 3ffefb90 3ffefb90 4020aa44  
23:08:44.371 -> 3ffffe40:  3fff018c 00000000 00000000 40207307  
23:08:44.418 -> 3ffffe50:  40204d16 40204d0e 40100929 4022150a  
23:08:44.465 -> 3ffffe60:  000005e2 000005e2 3ffe868c 40100ec3  
23:08:44.559 -> 3ffffe70:  00000000 4bc6a7f0 3a5e353f 00000001  
23:08:44.559 -> 3ffffe80:  3fff355c 00000020 3fff355c 401010a2  
23:08:44.654 -> 3ffffe90:  3ffef2d0 00000000 00000000 40100a5c  
23:08:44.654 -> 3ffffea0:  000040b0 3fff0060 0000012c 40221f7c  
23:08:44.748 -> 3ffffeb0:  00000534 00000534 3ffe868c 40100ec3  
23:08:44.748 -> 3ffffec0:  3ffe8630 00000000 3fff3394 3ffe8630  
23:08:44.844 -> 3ffffed0:  00000000 0000002b 00000020 3ffe8630  
23:08:44.892 -> 3ffffee0:  00000000 0000002b 3ffef770 4020744a  
23:08:44.939 -> 3ffffef0:  00000006 3fff2fec 3ffef770 402071be  
23:08:44.986 -> 3fffff00:  00000059 00000000 00000001 00000003  
23:08:45.034 -> 3fffff10:  00000001 3ffefc68 3ffef770 40206d7e  
23:08:45.081 -> 3fffff20:  402104d0 43b2a8c0 3ffef908 4021ac5f  
23:08:45.128 -> 3fffff30:  3fffff70 00000cea 3ffe863b 3ffe8630  
23:08:45.224 -> 3fffff40:  00000000 402055c0 3ffefc68 40206b83  
23:08:45.272 -> 3fffff50:  40204b25 3ffef92c 3ffefb72 3ffefd04  
23:08:45.320 -> 3fffff60:  402104d0 3ffefb72 3ffefc68 4020160c  
23:08:45.368 -> 3fffff70:  402104d0 43b2a8c0 402104d0 00000000  
23:08:45.416 -> 3fffff80:  402104d0 00ffffff 402104d0 01b2a8c0  
23:08:45.462 -> 3fffff90:  402104d0 21b2a8c0 feefeffe feefeffe  
23:08:45.510 -> 3fffffa0:  3fffdad0 00000000 3ffefcf0 4020be20  
23:08:45.558 -> 3fffffb0:  feefeffe feefeffe 3ffe8688 4010135d  
23:08:45.606 -> <<<stack<<<
23:08:45.654 -> 
23:08:45.654 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------

What does the error mean and how can I fix this?

A code is doing and going places where it's not supposed to.

After you installed the ESP Exception Decoder, copy and pasted the error message into the exception decoder and got a result, could you post the exception decoder's results?

Thanks for your help. I did what you recommended and got this:

Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x40206f00
EXCVADDR: 0x00000049

Decoding stack results
0x4020fcd8: tcp_slowtmr at core/tcp.c line 1469
0x4020fca4: tcp_slowtmr at core/tcp.c line 1445
0x4020a990: strstr_P at /workdir/repo/newlib/newlib/libc/sys/xtensa/string_pgmspace.c line 91
0x4020a9b4: strstr_P at /workdir/repo/newlib/newlib/libc/sys/xtensa/string_pgmspace.c line 105
0x4020aa44: memcmp_P at /workdir/repo/newlib/newlib/libc/sys/xtensa/string_pgmspace.c line 145
0x40207307: read_sleb128 at /workdir/repo/gcc-gnu/libgcc/unwind-pe.h line 162
0x40204d16: uart_read(uart_t*, char*, size_t) at C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\uart.cpp line 289
0x40204d0e: uart_read(uart_t*, char*, size_t) at C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\uart.cpp line 289
0x40100929: realloc(void*, size_t) at C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 889
0x40100a5c: realloc(void*, size_t) at C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 1097
0x4020744a: base_from_object at /workdir/repo/gcc-gnu/libgcc/unwind-dw2-fde.c line 272
0x40206d7e: DhcpServer::add_offer_options(unsigned char*) at C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\LwipDhcpServer.cpp line 390
0x402104d0: netif_add_LWIP2 at core/netif.c line 296
0x402055c0: run_scheduled_recurrent_functions() at C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/core_esp8266_features.h line 65
0x40204b25: settimeofday(timeval const*, timezone const*) at c:\users\admin\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\bits/std_function.h line 337
0x402104d0: netif_add_LWIP2 at core/netif.c line 296
0x4020160c: ESP8266WiFiGenericClass::_eventCallback(void*) at C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WiFi\src\ESP8266WiFiGeneric.cpp line 247
0x402104d0: netif_add_LWIP2 at core/netif.c line 296
0x402104d0: netif_add_LWIP2 at core/netif.c line 296
0x402104d0: netif_add_LWIP2 at core/netif.c line 296
0x402104d0: netif_add_LWIP2 at core/netif.c line 296
0x402104d0: netif_add_LWIP2 at core/netif.c line 296
0x4020be20: rshift at /workdir/repo/newlib/newlib/libc/stdlib/gdtoa-gethex.c line 90

Looks like one of the libraries is stomping over a ram location. It may take line by line uncommenting and commenting to find the issue. Good luck.

I had the same problem after updating the esp8266 board manager version to 3.0.2.
Now I went back to 2.7.4 and it works correctly again as before.
It took me a long time to find it out. I use the following versions:
Arduino IDE 1.8.19
mysql connector 1.2.0
wifi 1.2.6

Thanks for the tip. Going back to 2.7.4 solved it for me as well after trying to fix my code for hours.

You can also try to use my MySQL_MariaDB_Generic library to access to either MySQL or MariaDB database, using either ESP32/ESP8266 or any of Currently supported Boards

Thank you! Changing from 3.0.2 to 2.7.4 fixed the problem for me aswell