CentOS 7 "Could not create connection to database server" error - solution

CentOS 7 (most probably apply for Redhat and Fedora) has SELinux (stands for Security Enhanced Linux) active by default, and this disallow tomcat from remote connecting to MySQL database that is located on the same server as tomcat.

The solution to this is to allow tomcat to connect to databases (Permanently) using:

setsebool -P tomcat_can_network_connect_db 1

Then reboot if needed

Some other useful commands:

to check SELinux status:

sestatus

to see the permissions for tomcat

getsebool -a | grep tomcat

to make this change temporarly

setsebool tomcat_can_network_connect_db 1

to change the status for SELinux

sudo nano /etc/selinux/config

I hope this can help other people :slight_smile:

Thanks to @ibacher for clarifying the error origin

2 Likes

Very good practice for sharing solutions with the entire community! Thanks @hany :slight_smile:

1 Like