Skip to content

Instantly share code, notes, and snippets.

@mul14
Last active June 20, 2024 16:47
Show Gist options
  • Save mul14/0268636ae342c6012c6c29f88d9d25b6 to your computer and use it in GitHub Desktop.
Save mul14/0268636ae342c6012c6c29f88d9d25b6 to your computer and use it in GitHub Desktop.
How to set MySQL timezone with timezone name?

Check current MySQL timezone:

SELECT @@global.time_zone, @@session.time_zone;

The value might be SYSTEM, UTC, or your current MySQL timezone.

If you want to change the default MySQL timezone to something else (e.g Asia/Jakarta), run this query:

SET GLOBAL time_zone = 'Asia/Jakarta';
SET SESSION time_zone = 'Asia/Jakarta';

You might get an error "Query 1 ERROR at Line 1: : Unknown or incorrect time zone: 'Asia/Jakarta'".

To check your MySQL already have the timezone data:

SELECT * FROM mysql.time_zone_name;

If that query returns empty, you need to load the timezone to that table.

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -p mysql

You can execute the commands in backward-steps to set the default MySQL timezone.

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment