Just a warning that this error is a general database connectivity error that is caused for a multitude of reasons.
On a new install with separate ERPNext frontend and database servers, I got this because the permissions for the root user wasn’t set properly in the database.
Test from the client using:
mysql -h 192.168.1.42 -u root -p
Fix using:
grant all privileges on *.* to 'root'@'192.168.1.%' identified by 'yourPassword' with grant option;