I am struggeling to get a connection to my local MySQL database that is on a LAMP server, i have tried to get a connection with a Arduino WiFi Rev.2, Arduino Yùn Rev.1, a normal Arduino UNO connected to an ESP8266 and even a ESP-32. I have made a user in MySQL that is only allowed to connect from the IP address that the Arduino has, but whatever i try from the client or server side i can't get it to work.
I'm just using a little sketch i made to get a connection from the Arduino UNO WiFi Rev.2 to the server, I am using the MySQL library made by Dr. Charles Bell. and i have read though his manual for the lib and all but still, it won't work.
Here is my code for the connection:
#include <SPI.h>
#include <WiFiNINA.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include "arduino_passwds.h"
#include "arduino_usrs.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(127,0,0,1); //I am not using the local IP of the server in the original sketch.
char user[] = "MyUser"; // MySQL user login username
char password[] = "MyPasswd"; // MySQL user login password
int status = WL_IDLE_STATUS;
WiFiClient client;
MySQL_Connection conn((Client *)&client);
void setup()
{
Serial.begin(9600);
while (!Serial)
{
;
}
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed!");
while (true);
}
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
Serial.println("You're connected to the network");
printCurrentNet();
printWifiData();
Serial.println("Connecting to DB...");
if (conn.connect(server_addr, 3306, user, password))
{
delay(1000);
Serial.println("Success!");
}
else
{
Serial.println("Failed to connect to DB");
conn.close();
}
}
void loop()
{
delay(5000);
}
If you need any more info just ask and ill provide.