I cannot connect to MySQL server, but I still can open it via PHP Admin

These tools won’t work here, as external connections are not allowed in free hosting:

I am assuming you are getting this issue on a WordPress installation hosted on InfinityFree (and not in, let’s say, a local environment)?

Would it be possible to share your wp-config.php database configuration (the ones you shared above) formatted with three backticks at the beginning and end:

/* your code here */

I’m asking this because the forum applies its own formatting when your code isn’t posted in this format, which can make identifying a potential issue harder.