在一台服务器上,当我运行:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2009-05-30 16:54:29 |
+---------------------+
1 row in set (0.00 sec)

在另一台服务器上:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2009-05-30 20:01:43 |
+---------------------+
1 row in set (0.00 sec)

当前回答

要为当前会话设置它,请执行:

SET time_zone = timezonename;

其他回答

要在MariaDB中设置标准时区,必须转到50-server.cnf文件。

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

然后您可以在mysqld部分中输入以下条目。

default-time-zone='+01:00'

例子:

#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]

#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking

### Default timezone ###
default-time-zone='+01:00'

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.

必须通过配置文件进行更改,否则MariaDB服务器重启后将重置mysql表!

在我的例子中,解决方案是在高级设置中将serverTimezone参数设置为适当的值(CET表示我的时区)。

当我使用IntelliJ时,我使用它的数据库模块。当添加一个新的连接到数据库,并在“常规”选项卡中添加所有相关参数后,“测试连接”按钮上出现错误。同样,解决方案是在高级选项卡中设置serverTimezone参数。

在Windows (IIS)上,为了能够SET GLOBAL time_zone = 'Europe/Helsinki'(或其他什么),MySQL time_zone描述表需要首先填充。

我是从这个链接https://dev.mysql.com/downloads/timezones.html下载的

运行下载的SQL查询后,我能够设置全局time_zone和解决问题,我有SELECT NOW();返回的是格林尼治标准时间而不是英国夏令时。

古老的问题,还有一个建议:

如果你最近改变了操作系统的时区,例如通过:

unlink /etc/localtime
ln -s /etc/usr/share/zoneinfo/US/Eastern /etc/localtime

... MySQL(或MariaDB)直到重启db服务才会发现:

service mysqld restart

(or)

service mariadb restart

对于仍然有这个问题的人:

value="jdbc:mysql://localhost:3306/dbname?serverTimezone=UTC"

为我工作。只需在末尾附加?serverTimezone=UTC。