Can you try the below mentioned approaches:
Firstly check if MySQL or MariaDB server is started. Check service mysql status
Specify 127.0.0.1 as the host instead of localhost. That is, mysql -h 127.0.0.1 -u root instead of mysql -h localhost -u root. If you omit the host (mysql -u root), the MySQL client will implicitly use localhost.
For SingleStoreDB Cloud, change the socket value in the /etc/mysql/my.cnf file to the location of your SingleStoreDB Cloud socket file.
This should help resolve the issue.
AWS Lightsail Error Message saying “Error establishing a database connection"asked a year ago
Error establishing SSH connection to your instance.asked 2 months ago
Error establishing a database connection with RDS and OpenLiteSpeed AIMsasked 10 months ago
ERROR 2002 (HY000): Can't connect to local server through socket '/opt/bitnami/mariadb/tmp/mysql.sock' (111)asked 3 months ago
Cannot connect to SQL Server databaseAccepted Answerasked a year ago
Urgent Assistance: Error establishing a database connectionasked 24 days ago
Error establishing a database connectionasked 6 months ago
Exporting a database to AWSasked 4 months ago
AWS Lighthouse - site went down all of a sudden and now getting an Error establishing a database connectionasked 5 months ago
Not able to connect to MS-SQL Database by using SQL Server Management Studio installed on my local laptopasked 2 months ago