LindormTable 2.7.6 and later support multiple time zones. Earlier versions are fixed to UTC+8, which is the time zone of the Java Virtual Machine (JVM) running on the server. This document explains how to set a session-level time zone so that TIMESTAMP data is returned in the time zone your application expects.
How time zone settings work
LindormTable uses a session-level time zone variable. Each connection has its own independent time zone setting. Changing the session time zone does not affect other connections or the server default.
Only the TIMESTAMP data type is affected by time zone settings. DATE and TIME values are stored as plain strings and are always returned as-is.
| Data type | Format | Time zone sensitive |
|---|---|---|
| DATE | yyyy-mm-dd (for example, 2024-08-30) | No |
| TIME | hh:mm:ss (for example, 08:11:15) | No |
| TIMESTAMP | yyyy-mm-dd hh:mm:ss.SSS or epoch milliseconds (for example, 1724976675345) | Yes — displayed in the session time zone |
Prerequisites
Before you begin, make sure that:
Your LindormTable version is 2.7.6 or later. To check or upgrade your version, see Release notes of LindormTable and Upgrade the minor engine version of a Lindorm instance
Your application connects to LindormTable using the MySQL protocol. Time zone configuration is only supported over the MySQL protocol. For details, see Use the MySQL protocol to develop applications (recommended)
If you cannot upgrade LindormTable to 2.7.6 or later in the Lindorm console, contact technical support (DingTalk ID: s0s3eg3).
Set the session time zone
The default time zone is UTC+8. Use the SET statement to change the time zone for the current connection. The setting applies only to that connection and does not affect other connections or global defaults. For the full syntax, see Session variables.
-- Set to UTC
SET @@time_zone = 'UTC';
-- Set to UTC+8
SET @@time_zone = '+08:00';
-- Set to Shanghai local time
SET @@time_zone = 'Asia/Shanghai';To verify the current setting:
SELECT @@time_zone;Examples
MySQL command-line tool
For connection instructions, see Use a MySQL client to connect to and use LindormTable.
The following example creates a table and inserts a row with date, time, and timestamp values, then shows how the TIMESTAMP column changes when you switch time zones.
Set up the table:
-- Create the table
CREATE TABLE tb (p1 INT, c1 DATE, c2 TIME, c3 TIMESTAMP(3), PRIMARY KEY (p1));
-- Insert a row
UPSERT INTO tb (p1, c1, c2, c3) VALUES (1, '2024-08-30', '08:11:15', '2024-08-30 08:11:15.354');Query in UTC+8 (default):
Check the current time zone.
SELECT @@time_zone;Expected output:
+-------------+ | @@time_zone | +-------------+ | +08:00 | +-------------+Query the table.
SELECT * FROM tb;Expected output:
+------+------------+----------+-------------------------+ | p1 | c1 | c2 | c3 | +------+------------+----------+-------------------------+ | 1 | 2024-08-30 | 08:11:15 | 2024-08-30 08:11:15.354 | +------+------------+----------+-------------------------+
Switch to UTC and re-query:
Change the time zone to UTC.
SET @@time_zone = 'UTC';Confirm the change.
SELECT @@time_zone;Expected output:
+-------------+ | @@time_zone | +-------------+ | UTC | +-------------+Query the table again.
SELECT * FROM tb;Expected output:
+------+------------+----------+-------------------------+ | p1 | c1 | c2 | c3 | +------+------------+----------+-------------------------+ | 1 | 2024-08-30 | 08:11:15 | 2024-08-30 00:11:15.354 | +------+------------+----------+-------------------------+
The c1 (DATE) and c2 (TIME) values are unchanged because they are not time zone sensitive. The c3 (TIMESTAMP) value shifts from 08:11:15 to 00:11:15 — an 8-hour difference reflecting the conversion from UTC+8 to UTC.
Java
For connection instructions, see Use Java JDBC APIs to develop applications.
The MySQL Connector/J driver provides two parameters that work together to control the connection time zone:
| Parameter | Example value | Description |
|---|---|---|
connectionTimeZone | UTC | The time zone the driver uses for converting TIMESTAMP values on the client side. Defaults to the JVM time zone. |
forceConnectionTimeZoneToSession | true | When set to true, the driver executes SET time_zone at connection time, pushing connectionTimeZone to the server session. If your business runs in a region that does not use the UTC+8 time zone, we recommend that you add this parameter. |
Add both parameters to your connection string when your application runs outside UTC+8:
String url = "jdbc:mysql://ld-uf6k8yqb741t3****-proxy-sql-lindorm-public.lindorm.rds.aliyuncs.com:33060/"
+ database
+ "?sslMode=disabled"
+ "&allowPublicKeyRetrieval=true"
+ "&useServerPrepStmts=true"
+ "&useLocalSessionState=true"
+ "&rewriteBatchedStatements=true"
+ "&cachePrepStmts=true"
+ "&prepStmtCacheSize=100"
+ "&prepStmtCacheSqlLimit=50000000"
+ "&forceConnectionTimeZoneToSession=true";
Properties properties = new Properties();
properties.put("user", username);
properties.put("password", password);
// Get a connection
Connection connection = DriverManager.getConnection(url, properties);Python
For connection instructions, see Use mysql-connector-python to develop applications.
Pass the time_zone parameter in the connection call to set the session time zone at connect time:
| Parameter | Example value | Description |
|---|---|---|
time_zone | 'UTC' | Sets the session time zone on the server. Set this to the time zone where your application runs. |
connection = mysql.connector.connect(
host='<LindormTable endpoint for MySQL>',
port=33060,
user='<Username>',
passwd='<Password>',
database='<Database name>',
time_zone='<Time zone>' # for example, 'UTC' or 'Asia/Tokyo'
)Go
For connection instructions, see Use Go to develop applications.
The Golang MySQL Driver passes session variables through the connection string. String values must be URL-encoded: wrap the value in single quotes ('), then percent-encode those quotes as %27. For example, the string 'UTC' becomes %27UTC%27.
| Parameter | Example value | Description |
|---|---|---|
parseTime | true | Returns DATE and TIMESTAMP values as time.Time instead of raw strings. Required for the loc parameter to take effect. |
loc | Local | The Go time zone used when parsing time.Time values. Local uses the system time zone. Takes effect only when parseTime=true. |
time_zone | %27UTC%27 | Sets the session time zone on the server. The value must be URL-encoded — single quotes become %27. |
For more information on how the driver handles system variables, see System Variables.
urlString := fmt.Sprintf(
"%s:%s@tcp(%s:%d)/%s?timeout=%s&parseTime=true&loc=Local",
user, password, host, port, database, connectTimeout,
)
timeZoneValue := url.QueryEscape("'UTC'") // produces %27UTC%27
urlString = urlString + "&time_zone=" + timeZoneValue
db, err := sql.Open("mysql", urlString)
if err != nil {
panic(err.Error())
}What's next
Session variables — full list of session-level variables supported by LindormTable
Use the MySQL protocol to develop applications (recommended) — overview of MySQL protocol support in LindormTable