How do I solve “could not create connection to database” error?

Hi every one how to fixed the following error

???Error executing sql: create database if not 
exists `?` default character set utf8 - Could not 
create connection to database server. 
Attempted reconnect 3 times. Giving up.???

Unable to create the database. The password 
might be incorrect or the database is not 
started.

Kindly use pastebin to share the entire error log for easy identification of the problem.

it is very Urgent

It’s hard to solve a problem without looking at the error log. Just go to pastebin.com. Copy the error you got and paste in the white space in the pastebin link and share the link after creating it

Ok thank you

what are you trying t o do,are trying to set up openmrs>

@hafizurahman have you used pastebin.com like @jwnasambu told you? If you did please paste here the link to pastebin that we could follow to help you.

hello, I have the same problem as the original poster. My setup: virtualbox virtual machine centos 7 tomcat 7.0.76 mysql 5.6.47 war file 2.2.0 I can access the server as seen from the screenshot

any suggestions? and where I can find the error log? thank you

Now I tried core 2.3.0, still with same error tomcat service log can be checked in: https://pastebin.com/wiDPTFR2 Hopefully someone can help

So when searching for the error message in your logs, I came across this StackOverflow answer, which suggests that the issue is caused by a change in the default SELinux configuration on RHEL 7.4 and later (and, consequently, on CentOS) which, by default, disallows Tomcat from connecting to a local database via TCP. The answer there suggests disabling SELinux, which is one way to solve the issue. This other answer suggests a command that should allow Tomcat to connect to MySQL without totally disabling SELinux. Finally, this blog post has a suggested SELinux policy which will default to allowing Tomcat to connect to MySQL with SELinux running.

I don’t have any experience with any of the suggested fixes, but you might try that and see if the issue resolves itself.

1 Like

I will try to use the localhost which is a unix socket as far as I understand, and I will check your suggestions about SELinux, also as I understood there is another solution by using different server for mysql. I will try these solutions and come back to you. your help is much appreciated @ibacher

Disabling SELinux done the trick, even it is not good to disable it, but at least now I know the origin of the problem, thank you so much :slight_smile:

1 Like

Some notes for people who works with CentOS 7 to configure SELinux permissions:

to check SELinux status:

sestatus

to see the permissions for tomcat

getsebool -a | grep tomcat

to allow tomcat to connect to database

setsebool tomcat_can_network_connect_db 1

to make this change permanent

setsebool -P 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: