This relates to the solution to the problem of the previous WordPress database. But there is a specific problem in the corrupt WP database table.
At first I thought from the standard error message “Error establishing database connection” it was a simple fix. Only a problem between the MySQL username / password or the wrong database name. It turns out that what happens is that one or more tables in the WordPress database are damaged and need to be fixed.

The solution itself is easy. Please edit the wp-config.php file and add the following code:
define('WP_ALLOW_REPAIR', true);
/* That's all, stop editing! Happy blogging. */
Then open the name_domain.com/wp-admin/maint/repair.php link and just press the Repair Database button. If it’s smooth then all the solutions are already there.
But if it’s still problematic and a message appears like this:
The wp_options table is not okay. It is reporting the following error: Table is marked as crashed and last repair failed. WordPress will attempt to repair this tableā¦
Failed to repair the wp_options table. Error: Table is marked as crashed and last repair failed
So to fix it we have to manually pass SSH to the database server (MySQL / MariaDB is the same), or if shared hosting uses phpMyAdmin. What we need is the ability to execute SQL queries.
Please note the name of the table that mentioned the error in your WordPress, in my case and for example the wp_options table. So the SQL command:
repair table wp_options;