If WordPress says it cannot select the database or complains about a corrupted table, there is a repair page hidden inside it. It is off by default, and for good reason.
Add this line to wp-config.php:
define( 'WP_ALLOW_REPAIR', true );
Then open https://example.com/wp-admin/maint/repair.php. The page offers to repair the database, or to repair and optimize it, and it works even when the rest of the site is broken because it does not need you to be logged in.
That last part is the caveat, and the WordPress documentation says so itself: while the constant is on, anyone who can reach that URL can start a repair. So enable it only when you need it, and remove the line as soon as the problem is solved. I would not leave it in a config file overnight.
The repair itself uses the same MySQL commands you can run by hand, so on a server where I have shell access I would first try wp db check and wp db repair. This page is for the times you only have a file manager and a browser.
Make a backup of the database before you start, even if the tables look broken. A repair does not always bring everything back.
Further reading: Editing wp-config.php, WP_ALLOW_REPAIR (WordPress Advanced Administration)