MySQL_Connect not connect

I try connect to MySQL database with Arduino Nano and ENC28j60, but after 3 retry connection failed.
Here is the src:

#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(192,168,1,178);  // IP of the MySQL *server* here
char user[] = "arduino";              // MySQL user login username
char password[] = "secret";        // MySQL user login password

// Sample query
char INSERT_SQL[] = "insert into mylog.nfc_access (nfcuid, loggerid) values ('a1b2c3d4',1)";

#define MACADDRESS 0x00,0x01,0x02,0x03,0x04,0x05
#define MYIPADDR 192,168,1,188
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,1,1
#define MYGW 192,168,1,1
#define UARTBAUD 115200

uint8_t mac[6] = {MACADDRESS};
uint8_t myIP[4] = {MYIPADDR};
uint8_t myMASK[4] = {MYIPMASK};
uint8_t myDNS[4] = {MYDNS};
uint8_t myGW[4] = {MYGW};

EthernetClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
  Serial.begin(UARTBAUD);
  while (!Serial); // wait for serial port to connect
  Serial.println(F("Ethernet.begin..."));
  Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
  Serial.println(F("Connecting..."));
  if (conn.connect(server_addr, 3306, user, password)) {
    delay(1000);
  }
  else {
    Serial.println(F("Connection failed."));
    while(true);
  }
}


void loop() {
}

And here is the output in serial monitor:

Ethernet.begin...
Connecting...
...trying...
...got: 0 retrying...
...trying...
...got: 0 retrying...
...trying...
...got: 0 retrying...
Connection failed.

I checked the server, it's accessible the database by 'arduino' user from the network.
I tried to disable SSL on server but nothing happened.
I created user with this sql command:

CREATE USER 'arduino'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';
GRANT ALL ON mylog TO 'arduino'@'%';

What can I do?

Go to the SQL server and read the error logs to determine why the connection is being refused, if the connection is even getting to the SQL server.

You may need to open up or allow remote access. View the IP address of the attempted connection and open up the SQL server to remote access from the IP address your thingy is trying to connect with.

MySql's default behaviour is to reject all connection attempts that don't come from the machine it is running on. Have you changed that?

Yes, I tried from other computer on the network. I can connect to the sql server.

mysql -h 192.168.1.178 --user=arduino --password mylog

Error log display nothing. No access denied error appeared when I try connect from the arduino.

If the SQL server does not log the connection attempt, then the connection may not be getting to the SQL server.

One can use this method, ESP32 HTTP GET and HTTP POST with Arduino IDE | Random Nerd Tutorials. I use a Raspberry Pi (RPi) for mySQL dB connections and have the ESP32's send their data to the RPi via MQTT.

Because of this I tried disable SSL connections on mysql server. I can ping the Ethernet shield from the network, so Ethernet.begin is done, network connected. How can I check the networking between arduino and mysql server under Linux?

Did you do a search for "arduino ping"? Good luck.

Wireshark.

I don't found any package with wireshark from the arduino to the mysql server.
Ping is work, wireshark captured the ICMP packages.

That would explain why there's nothing in the log.

To check your filters, do you see packets from the computer that can connect to database?

Yes, I see packages in wireshark from other computer to mysql server.

Your mac address looks invented, I don't know if there are any rules regarding whether it's valid, but maybe try the one at the top of your program.

Ok, I tried with another hardware (Uno and WS5100) and it works now. When I tried ping sample with ENC28j60 it doesn't worked for me. Then I change the hardware and done. Thanks for ideas!

In some of the ways, spacing and the order of parameters in the MySql connection string does matters. So, stick to the standard format:

MysqlConn.ConnectionString = "Server=localhost;Port=1234;Database=My_Mysql_Database;Uid=root;Pwd=root;"

If the above connection string fails, try update your c# mysql connection string as shown below (without port variable as well):

MysqlConn.ConnectionString = "Server=localhost;Database=My_Mysql_Database;Uid=root;Pwd=root;"

Or, sometime the problem could be on your windows firewall, make sure your server allow access to all port associated with your mysql database.