ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
332 stars 133 forks source link

MySQL_Connector_Arduino ( ...got: 0 retrying... FAILED. ) #210

Closed salahrachidi closed 1 year ago

salahrachidi commented 1 year ago

i'm trying to connect to mysql db using ESP8266 and ESP8266WiFi.h library and it keeps showing me this error : Connecting to 1.618............... Connected to network My IP address is: 192.168.8.120 Connecting to SQL... ...trying... ...got: 0 retrying... ...trying... ...got: 0 retrying... ...trying... ...got: 0 retrying... FAILED. //****The code /* MySQL Connector/Arduino Example : connect by wifi

This example demonstrates how to connect to a MySQL server from an Arduino using an Arduino-compatible Wifi shield. Note that "compatible" means it must conform to the Ethernet class library or be a derivative with the same classes and methods.

For more information and documentation, visit the wiki: https://github.com/ChuckBell/MySQL_Connector_Arduino/wiki.

INSTRUCTIONS FOR USE

1) Change the address of the server to the IP address of the MySQL server 2) Change the user and password to a valid MySQL user and password 3) Change the SSID and pass to match your WiFi network 4) Connect a USB cable to your Arduino 5) Select the correct board and port 6) Compile and upload the sketch to your Arduino 7) Once uploaded, open Serial Monitor (use 115200 speed) and observe

If you do not see messages indicating you have a connection, refer to the manual for troubleshooting tips. The most common issues are the server is not accessible from the network or the user name and password is incorrect.

Created by: Dr. Charles A. Bell */

include // Use this for WiFi instead of Ethernet.h

include

include

IPAddress server_addr(127,0,0,1); // IP of the MySQL server here char user[] = "root"; // MySQL user login username char password[] = ""; // MySQL user login password

// Sample query char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";

// WiFi card example char ssid[] = "1.618"; // your SSID char pass[] = "45878923"; // your SSID Password

WiFiClient client; // Use this for WiFi instead of EthernetClient MySQL_Connection conn(&client); MySQL_Cursor* cursor;

void setup() { Serial.begin(115200); while (!Serial); // wait for serial port to connect. Needed for Leonardo only

// Begin WiFi section Serial.printf("\nConnecting to %s", ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }

// print out info about the connection: Serial.println("\nConnected to network"); Serial.print("My IP address is: "); Serial.println(WiFi.localIP());

Serial.print("Connecting to SQL... "); if (conn.connect(server_addr, 3306, user, password)) Serial.println("OK."); else Serial.println("FAILED.");

// create MySQL cursor object cursor = new MySQL_Cursor(&conn); }

void loop() { if (conn.connected()) cursor->execute(INSERT_SQL);

delay(5000); }

salahrachidi commented 1 year ago

i need help please ...

ChuckBell commented 1 year ago

Hi. The first thing I see is you must use the IP address for the MySQL server, not the loopback address. Tip: see the wiki for troubleshooting tips.

On Tue, May 16, 2023 at 12:10 salah rachidi @.***> wrote:

i need help please ...

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/210#issuecomment-1549967743, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYFUBAIUQ3TM4TLJNADXGORIFANCNFSM6AAAAAAYD4D2YA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

salahrachidi commented 1 year ago

@ChuckBell i'm running mysql on my computer i don't know how to get mysql server ip adress ! i tried to keep the default ip adress but it didn't work also

ChuckBell commented 1 year ago

Hi. In that case, use the IP address of your PC. Again, check the wiki for troubleshooting tips getting connected.

On Tue, May 16, 2023 at 16:27 salah rachidi @.***> wrote:

@ChuckBell https://github.com/ChuckBell i'm running mysql on my computer i don't know how to get mysql server ip adress ! i tried to keep the default ip adress but it didn't work also

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/210#issuecomment-1550314252, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYAR6FDLN55DYS6DL4TXGPPKLANCNFSM6AAAAAAYD4D2YA . You are receiving this because you were mentioned.Message ID: @.***>

salahrachidi commented 1 year ago

thank you soo much