iT邦幫忙

0

在使用ESP32連接MySQL時,遇到監控視窗卡在'Trying'的情況

  • 分享至 

  • xImage

各位大神好!最近嘗試用ESP32傳送資料到MySQL,但遇上解決不了的問題(附圖中)
https://ithelp.ithome.com.tw/upload/images/20240331/2016630352r3a9OvA4.png
我使用Arduino IDE編寫,當WiFi連接完成再來與MySQL連接卻卡住了,檢查WiFi、MySQL帳密都正確(在同一個區域網路中),port也正常沒被擋,奇怪的是MySQL能看到有嘗試登入但失敗,有點像連線逾時?請教各路大神是否知道哪裡出問題,或者是否有人遇過類似狀況呢?/images/emoticon/emoticon02.gif
附上MySQL連接程式碼

#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);
}
看更多先前的討論...收起先前的討論...
你有檢查mysql的權限嗎?
就是你登入的mysql的帳號密碼是什麼權限
ntustzeus iT邦新手 3 級 ‧ 2024-04-01 09:31:02 檢舉
開新user時,預設的存取權限應該是localhost,如果有log有嘗試登入的話可能是這個問題
f48834394 iT邦新手 5 級 ‧ 2024-04-02 00:01:20 檢舉
我在phpMyAdmin中有創建了使用者,全域權限為All privileges,主機名稱從localhost改為%,是這邊出現問題了嗎?
netstated iT邦新手 5 級 ‧ 2024-04-02 11:04:29 檢舉
允許外部登入?
f48834394 iT邦新手 5 級 ‧ 2024-04-02 14:03:57 檢舉
他允許外部登入,奇怪的是我使用python能成功登入並上傳資訊但arduino ide 卻會出現卡在”trying”這種情況。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答