I am using php mysqli_connect for login to a MySQL database (all on localhost)
mysqli_connect
ALTER USER 'mysqlUsername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
Remove quotes (') after ALTER USER and keep quote (') after mysql_native_password BY
ALTER USER
mysql_native_password BY
It is working for me also.