Skip to content

Instantly share code, notes, and snippets.

@mul14
Last active March 12, 2026 10:04
Show Gist options
  • Select an option

  • Save mul14/0268636ae342c6012c6c29f88d9d25b6 to your computer and use it in GitHub Desktop.

Select an option

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.

Notes:

If you’re using DBngin, the mysql_tzinfo_to_sql command might not be available in your $PATH. In that case, you need to use the absolute path to run it.

/Users/Shared/DBngin/mariadb/10.11.6_arm/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

/Users/Shared/DBngin/mysql/8.0.33/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

/Users/Shared/DBngin/mysql/8.2/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

References:

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