If you are facing this error of Error establishing a database connection while installing WordPress or some other API, whether in Windows or Linux, then you would probably be missing the configuration of database connection in your config file, which is wp-config.php in WordPress.
For resolving this issue, you first have to make changes in your configuration file wp-config.php.
Open up wp-config.php file in your IDE, which will be existing in your wordpress folder, and see if the DB name, DB user and DB password variables are defined properly.
Note: You check check out the following URL for Free PHP IDEs in Ubntu (Linux):
Or if you have not yet created the database for WordPress, then simply create one through any MySql Client, with the name of “wp” or whatever has been mentioned in the DB_NAME variable of wp-config.php file.
Hope this will help you in resolving the issue of Error establishing a database connection in Windows or Linux.