# Upgrade mysql-connector to at least v8.0.23 for platform 2.4.0

**URL:** <https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068>\
**Category:** Development\
**Tags:** platform\
**Created:** [July 14, 2021, 6:37am UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068 "2021-07-14T06:37:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![corneliouzbett](https://talk.openmrs.org/user_avatar/talk.openmrs.org/corneliouzbett/32/15464_2.png) [@corneliouzbett](https://talk.openmrs.org/u/corneliouzbett)\
**Post date:** [July 14, 2021, 6:37am UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068/1 "2021-07-14T06:37:08Z")

</div>

The current version of MySQL-connector ([v8.0.21](https://github.com/openmrs/openmrs-core/blob/2.4.0/pom.xml#L423)) doesn’t provide support to set SERVER TIMEZONE via the connection string(it’s a bug). Due to this fact, the server timezone defaults to UTC. This is problematic!! Causes errors building search Index for some patients ~ affects patient search

To fix the issue. IMO I’ve got two options here:

- Upgrade mysql-connector to at least `v8.0.23`
- Revert mysql-connector to use 5.x (the one used by previous platform version 2.3.x)

This commit [FORCED TO SET SERVER TIMEZONE IN CONNECT STRING.](https://github.com/mysql/mysql-connector-j/commit/f5f8bf087b6d603d8d55254fa99d47ca1a57f9b4) Fixes the above issue. However, with this upgrade comes incompatibility issues and some breaking changes. I tried upgrading mysql-connector to `v8.0.25`, couldn’t brought up the server. I encoutered errors one after the other, for example; this might implies upgrade liquibase-core to a higher version.

```auto
java.lang.ClassCastException: class java.time.LocalDateTime cannot be cast to class java.lang.String (java.time.LocalDateTime and java.lang.String are in module java.base of loader 'bootstrap')
amrs-upgrade | at liquibase.changelog.StandardChangeLogHistoryService.getRanChangeSets(StandardChangeLogHistoryService.java:328) ~[liquibase-core-3.10.2.jar:?]
amrs-upgrade | at liquibase.changelog.AbstractChangeLogHistoryService.upgradeChecksums(AbstractChangeLogHistoryService.java:66) ~[liquibase-core-3.10.2.jar:?]
amrs-upgrade | at liquibase.changelog.StandardChangeLogHistoryService.upgradeChecksums(StandardChangeLogHistoryService.java:297) ~[liquibase-core-3.10.2.jar:?]

```

Option two is much safer(I chose to do this), this how i fix the issue checkout tag 2.4.0, downgrade mysql-connector to `v5.1.47` (latest in 5.1.x), change hibernate connection driver class from `com.mysql.cj.jdbc.Driver` to `com.mysql.jdbc.Driver`. Now I can set `serverTimezone=EAT` in the connection string.

Is there a better way of fixing the issue above?

cc: @dkayiwa @ibacher @aojwang [@dev5](https://talk.openmrs.org/groups/dev5)

---

<div class="post-metadata">

**Author:** ![mksd](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mksd/32/11729_2.png) [@mksd](https://talk.openmrs.org/u/mksd)\
**Post date:** [July 14, 2021, 7:32am UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068/2 "2021-07-14T07:32:41Z")

</div>

Thanks @corneliouzbett that’s interesting, we’ve run into the exact same issue right @frederic.deniger @jfigueiredo?

---

<div class="post-metadata">

**Author:** ![jfigueiredo](https://talk.openmrs.org/letter_avatar/jfigueiredo/32/5_5575768a8748004e209b776fc1b2916d.png) [@jfigueiredo](https://talk.openmrs.org/u/jfigueiredo)\
**Post date:** [July 14, 2021, 8:08am UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068/3 "2021-07-14T08:08:39Z")

</div>

> [@corneliouzbett](#):
>
> e to this fact, the server timezone defaults to UTC

Hello @corneliouzbett , as @mksd said, we have a similar problem, we add some parameters to the driver to make sure that all the dates are converted to UTC when we are saving database using ( and converted back when getting the dates) :

```auto
OPENMRS_JDBC_EXTRA_PARAMETERS=&serverTimezone\=Etc/UTC&useLegacyDatetimeCode=true&noTimezoneConversionForTimeType=true&useTimezone=true

```

But then we had 2 problems:

1º The time parameter is converted to UTC when saving but does **not** convert back when getting the time from DB, we can fix this with `noTimezoneConversionForTimeType=true` ( so we don’t convert time types)

2º The same as the above happens on the `date` type, but here we don’t have a solution for this.

Bottom line is, the main problem we have is with MySQL `time` and `date` types. When we are working with `datetime` it works well.

CC @frederic.deniger

---

<div class="post-metadata">

**Author:** ![corneliouzbett](https://talk.openmrs.org/user_avatar/talk.openmrs.org/corneliouzbett/32/15464_2.png) [@corneliouzbett](https://talk.openmrs.org/u/corneliouzbett)\
**Post date:** [July 14, 2021, 8:38am UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068/4 "2021-07-14T08:38:41Z")

</div>

> [@jfigueiredo](#):
>
> Bottom line is, the main problem we have is with MySQL `time` and `date` types. When we are working with `datetime` it works well.

I would blame MySQL-connector. Have you tried using a different version of MySQL-connector? `8.1.23` or higher version

---

<div class="post-metadata">

**Author:** ![aojwang](https://talk.openmrs.org/letter_avatar/aojwang/32/5_5575768a8748004e209b776fc1b2916d.png) [@aojwang](https://talk.openmrs.org/u/aojwang)\
**Post date:** [July 14, 2021, 11:55am UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068/5 "2021-07-14T11:55:20Z")

</div>

We had to downgrade the platform to 2.3.3 for KenyaEMR upgrade.

---

<div class="post-metadata">

**Author:** ![ibacher](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ibacher/32/19751_2.png) [@ibacher](https://talk.openmrs.org/u/ibacher)\
**Post date:** [July 14, 2021, 5:03pm UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068/6 "2021-07-14T17:03:52Z")

</div>

Unfortunately, you’ll probably run into [this issue](https://talk.openmrs.org/t/typecasting-error-during-openmrs-setup/31816), which is caused by Liquibase not being aware of the change to MySQL connector (8.0.23 really should’ve been 8.1.0). I’m [working on fixing that](https://github.com/openmrs/openmrs-core/pull/3820).

---

<div class="post-metadata">

**Author:** ![frederic.deniger](https://talk.openmrs.org/user_avatar/talk.openmrs.org/frederic.deniger/32/15789_2.png) [@frederic.deniger](https://talk.openmrs.org/u/frederic.deniger)\
**Post date:** [July 15, 2021, 1:34pm UTC](https://talk.openmrs.org/t/upgrade-mysql-connector-to-at-least-v8-0-23-for-platform-2-4-0/34068/7 "2021-07-15T13:34:00Z")

</div>

Hello @corneliouzbett

Yes we tried the latest MySQL-connector version but the issue was still here and we faced an issue with Liquibase ( see @ibacher message).

From my point of view, we should not try to configure the MySQL driver to manage Timezone but it should be managed by OpenMRS. @jfigueiredo did some PRs for that 🙂
