Connecting Arduino to MySQL

Hi everyone,

I'm trying to make a connection from my Arduino Mega to RaspberryPi3 which contains the database. The problem is I cant seem to make connection from arduino to mysql, is there anything wrong with my code? Serial Monitor always shows 'Connection Failed.'. Does it have anything to do with the port 3306? like allow it or something? I am very new to arduino and programming so any help will be appreciated. TIA

If it helps, my project is to fetch stored data (password) from MySQL server using phpmyadmin to unlock a door. so i want to validate the password to control the door

connecttest.ino (1.85 KB)

A common reason for this is that default behaviour by mysql is to reject connections that didn't originate on the server itself. Your logs on the Pi should show you this.

If that's your issue, you have to change the config for the database. Search for mysql bind-address.