Weird, since I could actually connect to the DB using mysql client and the same credentials.
Since mysql client from front end works, I've tested php connectivity. For this I've put together the following small script in a file called conn.php and put the file in /var/www/html/wordpress/
Next I opened the browser and executed the php script which resulted in an expected connection error:
At this point I just run the same script, but this time interactively from php command line:
And I got a less expected connection successful message. By default SELinux is enabled and it will not allow httpd to talk to the mysql service. A quick test is to temporarily disable SELinux:
and running again the script will connect successfully:
So the main culprit is SELinux. Going forward there are 2 options: disable SELinux permanently (which is acceptable in demo labs) or enable Apache to connect to other service by changing the SELinux policy (which will be another post)