It is also worth nothing to confirm that the database the WordPress is trying to connect to actually exists and that the db server indeed supports ‘localhost’ or ‘127.0.0.1’.
Otherwise, as mentioned previously, confirm the db user has full privileges to access the database.