For newer mediawiki versions, there are some pitfalls that breaks the mysql connection. Some attempts to fix are:
Insert the port number on Database Host:
$wgDBserver = "localhost:3306";
On some old LocalSettings.php, there are active configurations for PostgreSQL besides the Mysql config. Erase or comment it.
# Postgres specific settings
# $wgDBport ...