Question

How can I change timezone for Mysql Database? (Api didn't work)

Hello everyone! I’m having some trouble changing the time zone on mysql server.

I have an App (Hosted here) which saves the datetime to my database, (I don’t explicity tell it the date and time, I just set the field on the db to current timestamp)

Whenever my App calls for the insertion, I get the wrong timezone (4 hours later than it is)

However when I manually send the SQL for insert (also not giving it any value) the time is right.

Here’s the config from the api.

"config": {
        "default_time_zone": "America/Montevideo",
        "interactive_timeout": 50400,
        "max_allowed_packet": 67108864,
        "sql_mode": "ANSI,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,STRICT_ALL_TABLES",
        "sql_require_primary_key": **true**,
        "wait_timeout": 50400,
        "innodb_ft_min_token_size": 3,
        "innodb_ft_server_stopword_table": "",
        "innodb_print_all_deadlocks": **false**,
        "innodb_rollback_on_timeout": **false**,
        "slow_query_log": **false**,
        "long_query_time": 10,
        "backup_hour": 17,
        "backup_minute": 43
    }

Any ideas how to fix it? Thanks in advance


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
June 21, 2023

Hey @fea5b15c6f1a44a09199ee55be0a4e,

So you, basically have the proper config for your MySQL Managed Database.

As for your App, basically, as it has a different timezone, when the SQL insert query is called from there you get the Apps timezone.

This has been discussed here

https://www.digitalocean.com/community/questions/how-to-adjust-the-server-timezone-in-app-platform

You can set the timezone with an TZ environment variable, for example:

TZ='Africa/Lagos'

Hope this helps!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel