Skip to content

Instantly share code, notes, and snippets.

@x-magic
Forked from brianburridge/gist:11298396
Last active October 8, 2023 12:54
Show Gist options
  • Save x-magic/7c44cad0bebe0fd9c998099649b5cb23 to your computer and use it in GitHub Desktop.
Save x-magic/7c44cad0bebe0fd9c998099649b5cb23 to your computer and use it in GitHub Desktop.
How to load MySQL/MariaDB time zone tables from macOS tzdata files

The easiest way to load the MySQL Time Zone tables from your macOS tzdata is via this command:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

Once the file is imported, you'll need to restart MySQL or MariaDB:

# Determine if you have MySQL or MariaDB
brew list

# Then, restart the service
brew services restart mysql  # If you have MySQL
brew services restart mariadb  # If you have MariaDB

Now that you have restarted MySQL, there is a simple test to check that the time zones are loaded. Launch the MySQL command line:

mysql -u root

Note: add -p if you need to enter a password to access your mysql db as root.

Once at the MySQL prompt, run this select:

SELECT CONVERT_TZ(now(), 'UTC', 'Australia/Melbourne');

If either time zone does not exist in your time zone table, you will get back a 'NULL' value in the converted column. If both exist, you'll get back a timestamp and you're ready to go.

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