Bitbucket 7.6.0 not connecting to MySQL 8.0
Asked by Fabrizio Santini:

I am trying to upgrade our old Bitbucket instance to the new 7.6.0 version. I can't pass the database setup because it can't connect to MySQL 8.0.21. Both Bitbucket and MySQL run in separate Docker containers. New instances of Jira and Confluence (those too are running in separate Docker containers) can connect normaly without too much trouble.

This is the error:

```
The configuration entered is not valid. A database connection could not be established. Please check your configuration and try again.	com.atlassian.stash.internal.db.DefaultDatabaseManager.validateConfiguration(DefaultDatabaseManager.java:217)	com.atlassian.stash.internal.migration.DefaultDatabaseMigrationService.validateConfiguration(DefaultDatabaseMigrationService.java:85)	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	...Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe last packet successfully received from the server was 4 milliseconds ago.  The last packet sent successfully to the server was 4 milliseconds ago.	org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)	com.atlassian.stash.internal.db.DefaultDatabaseValidator.validate(DefaultDatabaseValidator.java:43)	com.atlassian.stash.internal.db.DefaultDatabaseManager.validateConfiguration(DefaultDatabaseManager.java:214)	...Communications link failureThe last packet successfully received from the server was 4 milliseconds ago.  The last packet sent successfully to the server was 4 milliseconds ago.	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)	...Received fatal alert: protocol_version	sun.security.ssl.Alerts.getSSLException(Alerts.java:214)	sun.security.ssl.Alerts.getSSLException(Alerts.java:159)	sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2041)	...
```


Answers:
author: Aaron
body: Hey [@Fabrizio Santini](/t5/user/viewprofilepage/user-id/894769)!

A few things stand out to me here that make this a bit tricky.

> I am trying to upgrade our old Bitbucket instance to the new 7.6.0 version. I can't pass the database setup

A regular upgrade should **not**bring you to the database setup page. If you are doing a test upgrade of an already existing instance, you won't need to set up the DB connection again. If you are getting that page it means that either:

1. Your Bitbucket home was changed and you are not pointing to the correct database
2. Your bitbucket.properties file is not readable/move/no longer exists.

If you are just trying to install a fresh 7.6.0 instance than the above can be ignored. Otherwise, you need to make sure your Bitbucket home and shared directory are where you expect them to be.

Onto the error itself.

```
Received fatal alert: protocol_version sun.security.ssl.Alerts.getSSLException(Alerts.java:214) sun.security.ssl.Alerts.getSSLException(Alerts.java:159) sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2041)
```

This is an SSL error being thrown to Bitbucket. I haven't seen anything specific to Bitbucket, but I did come across <https://support.huaweicloud.com/intl/en-us/trouble-rds/rds_12_0005.html>

So some possibilities are:

1. JVM is too old to use the correct cipher suite.
2. JVM isn't using the right cipher suite.
3. Misconfigured MySQL expecting incorrect information.

So what can we do?

1. The easiest thing to do if possible would be to not use SSL for the MySQL connection. At the very least you'll get a different error if something is still configured incorrectly.
2. Based on the above document you could upgrade your system Java.
3. You could also try to add "-Dhttps.protocols=TLSv1.2" to the _start-webapp.sh file on the JVM_SUPPORT_RECOMMENDED_ARGS line (note you will have to uncomment that line). This assumes MySQL is expecting TLSv1.2. I don't know if that is the case for your environment.

I hope this helps!

Regards,  
Aaron Levinson  
Dev Tools Support Engineer


author: Ana Retamal
body: Hi [@Fabrizio Santini](/t5/user/viewprofilepage/user-id/894769), thanks for reaching out!

Please note that while MySQL is supported by Bitbucket Server, it's currently ***not*** recommended especially in larger instances, due to inherent performance and deadlock issues that occur in this database engine under heavy load. You can see [Connecting Bitbucket Server to MySQL](https://confluence.atlassian.com/bitbucketserver/connecting-bitbucket-server-to-mysql-776640382.html) for more information.

That said, let's look at a few things to make sure the configuration has been set correctly. First, let's start by making sure that the Bitbucket container is able to see the MySQL container on the network. You can check if the container is on the same docker network and try a ping or telnet to confirm if they can reach each other.  
Secondly, you'd also need to review if your MySQL setup is allowing connections from all the hosts on the network, as it's possible to restrict which IP addresses are able to connect to MySQL.  
We also suggest that you check the steps in [this thread](https://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai).  
I hope the recommendations below help you, Fabrizio! If it does, please mark the answer as accepted so other people can find it. If it doesn't, let us know what were the results you got so we can continue troubleshooting your issue.  
Best regards,  
Ana


Tags: bitbucket-server

server