title: How can I connect to database from Arduino?
body: <p>I want to transfer the data from the database to Arduino. For this, I am using MYSQL_Connector library in Arduino. But I'm getting error like this: "Connection Failed". I cannot connect to database. Also, I'm using XAMPP server.</p>
  
  <p>I checked MYSQL server's IP address, port and username-password. </p>
  
  <pre><code>#include &lt;SPI.h&gt;
  #include &lt;Ethernet.h&gt;
  #include &lt;MySQL_Connection.h&gt;
  #include &lt;MySQL_Cursor.h&gt;
  
  byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  
  IPAddress server_addr(x,x,x,x);  // the IP address to that of the system on which my MySQL server is set up
  char user[] = "user";              // MySQL user login username
  char password[] = "1234";        // MySQL user login password
  
  
  // Sample query
  char query[] = "SELECT id FROM world.city";
  
  EthernetClient client;
  MySQL_Connection conn((Client *)&amp;client);
  
  void setup() {
    Serial.begin(9600);
    while (!Serial); // wait for serial port to connect
    Ethernet.begin(mac_addr);
    Serial.println("Connecting...");
    if (conn.connect(server_addr, 8080, user, password)) {
      delay(1000);
    }
    else
      Serial.println("Connection failed.");
  }
  </code></pre>