if you're using docker and connect to the database server that resides on the host you'll need to use %.
If you've created a mysql user as YOUR-USER@localhost you won't be able to connect.
the solution is to update the mysql.user table but not directly.
RENAME USER 'YOUR-USER'@'localhost' TO 'YOUR-USER'@'%';
Sometimes you've host to use : 172.17.0.1 instead of host.docker.internal if you can't connect