MySQL

Connect

Use -u param to set username, use -p to indicate password. Be sure to replace greptime_user(username) and greptime_pwd(password) with your own username and password:

  1. mysql -h 127.0.0.1 -P 4002 -u greptime_user -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 8
  5. Server version: 5.1.10-alpha-msql-proxy Greptime
  6. Copyright (c) 2000, 2023, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql>

Table management

Please refer to Table Management.

Write data

Please refer to SQL.

Query data

Please refer to SQL.

Time zone

GreptimeDB’s MySQL protocol interface follows original MySQL on how to deal with time zone.

By default, MySQL uses its server time zone for timestamp. To override, you can set time_zone variable for current session using SQL statement SET time_zone = '<value>';. The value of time_zone can be any of:

  • The server’s time zone: SYSTEM.
  • Offset to UTC such as +08:00.
  • Any named time zone like Europe/Berlin.

Some MySQL clients, such as Grafana MySQL data source, allow you to set the time zone for the current session. You can also use the above values when setting the time zone.

You can use SELECT to check the current time zone settings. For example:

  1. SELECT @@system_time_zone, @@time_zone;

The result shows that both the system time zone and the session time zone are set to UTC:

  1. +--------------------+-------------+
  2. | @@system_time_zone | @@time_zone |
  3. +--------------------+-------------+
  4. | UTC | UTC |
  5. +--------------------+-------------+

Change the session time zone to +1:00:

  1. SET time_zone = '+1:00'

Then you can see the difference between the system time zone and the session time zone:

  1. SELECT @@system_time_zone, @@time_zone;
  2. +--------------------+-------------+
  3. | @@system_time_zone | @@time_zone |
  4. +--------------------+-------------+
  5. | UTC | +01:00 |
  6. +--------------------+-------------+

For information on how the time zone affects data inserts and queries, please refer to the SQL documents in the write data and query data sections.