Arduino and MySQL Connector problem

Hello everyone,
I’m trying to create a project which is writing data to a database using Arduino.
My Arduino (UNO) is connected to the PC with a USB Cable so I don’t have to use an ethernet Shield.
I’ve already created a database (phpMyAdmin) called ‘arduino’ that contains a table called ‘users’,
I’ve also downloaded the MySQL library in Arduino and I’ve written this code willing to insert this line on my database but it didn’t work.

Can anyone please help me detect where the problem is or if I have to add something.
Thanks in advance.

#include<mysql.h>
char *host, *user, *pass, *db;

void setup()
{
  Serial.begin(9600);
  host="localhost";
  user="root";
  pass="";
  db="arduino";

  if (mysql_connect(host,user,pass,db))
  {
   Serial.print(" Connected to ");
   Serial.println(host);
   int result=mysql_query("INSERT INTO users (`id`, `name`) VALUES(`2`, `BBBB`)");
        if(result) {
             
                  Serial.println("Query executed"); 
                  }
        else { 
                   Serial.println("Query execution failed.");
             }
  }
  else { 
       Serial.println("Connection failed.");
       }
}
void loop() {}
  host="localhost";

"localhost" means that the client and server are running on the same machine. Your MySQL database is NOT running on the Arduino, so this host name is nonsense.

So I have to change "localhost" to "127.0.0.1" ?

MREG:
So I have to change "localhost" to "127.0.0.1" ?

No. 127.0.0.1 is the IP address that corresponds to localhost.

You MUST determine the IP address of the machine that you want to talk to, and use that as the host value.

Sorry but I don’t understand… I mean the Arduino is connected to the same machine where my database is created

I mean the Arduino is connected to the same machine where my database is created

The Arduino needs to know the IP address of that machine. If the Arduino is not wearing an Ethernet shield, the mysql library won't work. It uses TCP/IP to talk to the host.

Means that it is necessary to use an Ethernet Shield ?

By the way, I've tried with the @IP of my machine but still don't work.

Means that it is necessary to use an Ethernet Shield ?

Or a WiFi shield.

Or, develop an application on the PC that can read the serial port and store the data in the MySQL database.

Alright, thank you.