mysql - Php Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'fobos'@'localhost' (using password: YES)

I have problems with connecting to the Mysql database (v5 and v8). If user is root that it's ok but if I create user 'fobos' I have connection error 1045 (error message PDOException: SQLSTATE[HY000] [1045] Access denied for user 'fobos'@'localhost' (using password: YES) in vms\public\staff\visitors\vms.php on line 14). I have no idea why this is happening.

Mysql -> create user fobos

SELECT user, host FROM mysql.user

+

php

   {-code-3}

Answer

--------+

Answer

-+ | user | host | +

Answer

--------+

Answer

-+ | debian-sys-maint | localhost | | fobos | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +

Answer

--------+

Answer

-+ CREATE USER 'fobos'@'localhost' IDENTIFIED BY '$zP_jaGA5xAE@"8~7TpdM'; GRANT ALL PRIVILEGES ON visitor_managment_system.* TO 'fobos'@'localhost' IDENTIFIED BY '$zP_jaGA5xAE@"8~7TpdM';|||public function __construct() { $this->connect = new PDO("mysql:host = localhost; dbname = visitor_managment_system","fobos", '$zP_jaGA5xAE@\"8~7TpdM'); }

Answer

Solution:

try FLUSH PRIVILEGES command in mysql cli

Source