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

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)

当前回答

在MySQL Workbench 8.0的服务器选项卡下,如果你选择状态和系统变量,你可以在这里设置它。

其他回答

要在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表!

如果您正在使用MySql Workbench,您可以通过打开管理员视图并选择Advanced选项卡来设置这一点。顶部部分是“Localization”,第一个复选框应该是“default-time-zone”。选中复选框,然后输入您想要的时区,重新启动服务器,您应该可以开始了。

您可以在启动服务器时指定服务器的默认时区,请参阅http://dev.mysql.com/doc/refman/5.1/en/server-options.html,特别是——default-time-zone=timezone选项。可以查看全局时区和会话时区

SELECT @@global.time_zone, @@session.time_zone;

使用set语句设置其中一个或两个,更多细节请参见http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html。

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

SET time_zone = timezonename;

请记住,“国家/地区”有时不起作用……这个问题与操作系统、MySQL版本和硬件无关——我从2003年FreeBSD 4和Slackware Linux到今天都遇到过这个问题。MySQL从版本3到最新的源中继。这很奇怪,但确实发生了。例如:

root@Ubuntu# ls -la /usr/share/zoneinfo/US
total 8

drwxr-xr-x  2 root root 4096 Apr 10  2013 .
drwxr-xr-x 22 root root 4096 Apr 10  2013 ..
lrwxrwxrwx  1 root root   18 Jul  8 22:33 Alaska -> ../SystemV/YST9YDT
lrwxrwxrwx  1 root root   21 Jul  8 22:33 Aleutian -> ../posix/America/Adak
lrwxrwxrwx  1 root root   15 Jul  8 22:33 Arizona -> ../SystemV/MST7
lrwxrwxrwx  1 root root   18 Jul  8 22:33 Central -> ../SystemV/CST6CDT
lrwxrwxrwx  1 root root   18 Jul  8 22:33 Eastern -> ../SystemV/EST5EDT
lrwxrwxrwx  1 root root   37 Jul  8 22:33 East-Indiana -> ../posix/America/Indiana/Indianapolis
lrwxrwxrwx  1 root root   19 Jul  8 22:33 Hawaii -> ../Pacific/Honolulu
lrwxrwxrwx  1 root root   24 Jul  8 22:33 Indiana-Starke -> ../posix/America/Knox_IN
lrwxrwxrwx  1 root root   24 Jul  8 22:33 Michigan -> ../posix/America/Detroit
lrwxrwxrwx  1 root root   18 Jul  8 22:33 Mountain -> ../SystemV/MST7MDT
lrwxrwxrwx  1 root root   18 Jul  8 22:33 Pacific -> ../SystemV/PST8PDT
lrwxrwxrwx  1 root root   18 Jul  8 22:33 Pacific-New -> ../SystemV/PST8PDT
lrwxrwxrwx  1 root root   20 Jul  8 22:33 Samoa -> ../Pacific/Pago_Pago
root@Ubuntu#

这样的陈述应该是有用的:

SET time_zone='US/Eastern';

但你有一个问题:

错误码:1298。未知或不正确的时区:“EUS/Eastern”

查看区域信息目录中的子文件夹,并查看符号链接的实际文件名,在本例中为EST5EDT。那就试试下面这句话:

SET time_zone='EST5EDT';

而且它确实像它应该的那样工作!:)记住这个技巧;我还没有在MySQL手册和官方文档中看到它的文档。但是阅读相应的文档是必须要做的事情:MySQL 5.5时区官方文档-不要忘记像这样将时区数据加载到服务器中(以root用户运行!):

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

技巧1 -它必须完全在MySQL根用户下完成。即使用户对MySQL数据库有完全的访问权限,它也可能失败或产生无法工作的结果-我自己看到了故障。