1

Service application is nodejs It is using mysql connection pool.

Currently, we will plan to sell service to another country What is the best way to set timezone?

timezone setting execute, and query execute? Like "Set timezone='UTC'; SELECT * FROM user;"

1

To setup the default Time Zone, you can edit the global variable system_time_zone (SET GLOBAL). You most likely want to change that on the configuration file so it persists after a reboot.

Timezones can be numerical or can use alias if setup properly.

To setup a client custom timezone, the right way is to SET SESSION time_zone ='<your timezone>';

Details at https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html

Most connection pools will destroy or cleanup the connection after usage and reset to the default, in any case, if they can vary per client, you want to set those up after each connection by running the SET SESSION command above.

Having said that, I would strongly recommend to handle timezones on application (presentation) layer and work only in a single timezone on server side (on UTC, preferably, or the local timezone only). While MySQL support is not bad, it can be confusing when handling multiple timezones (a 23:59:60 second, daylight saving changes, etc.). It may take a hard one-time conversion but it will be worth in the long term.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.