Servertimezone Mysql Phpstorm



  1. Mysql Servertimezone Asia Shanghai
  2. Mysql Servertimezone Utc+8
  3. Jdbc Mysql Servertimezone

PhpStorm is also available as a snap package. If you’re on Ubuntu 16.04 or later, you can install PhpStorm from the command line. Sudo snap install phpstorm -classic. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. At sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method). Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually There are two reasons Android turn Java, the first pit, record what the future can no longer encounter this problem, this problem is: 1. Your MySQL does not set the time zone 2. Your MySQL driver is not synchronized.

This section describes the time zone settings maintained by MySQL, how to load the system tables required for named time support, how to stay current with time zone changes, and how to enable leap-second support.

Beginning with MySQL 8.0.19, time zone offsets are also supported for inserted datetime values; see The DATE, DATETIME, and TIMESTAMP Types, for more information.

For information about time zone settings in replication setups, see Replication and System Functions and Replication and Time Zones.

MySQL Server maintains several time zone settings:

  • The system time zone. When the server starts, it attempts to determine the time zone of the host machine automatically and uses it to set the system_time_zone system variable. The value does not change thereafter.

    To explicitly specify the system time zone for MySQL Server at startup, set the TZ environment variable before you start mysqld. If you start the server using mysqld_safe, its --timezone option provides another way to set the system time zone. The permissible values for TZ and --timezone are system dependent. Consult your operating system documentation to see what values are acceptable.

  • The server current time zone. The global time_zone system variable indicates the time zone the server currently is operating in. The initial time_zone value is 'SYSTEM', which indicates that the server time zone is the same as the system time zone.

    If set to SYSTEM, every MySQL function call that requires a time zone calculation makes a system library call to determine the current system time zone. This call may be protected by a global mutex, resulting in contention.

    The initial global server time zone value can be specified explicitly at startup with the --default-time-zone option on the command line, or you can use the following line in an option file:

    If you have the SYSTEM_VARIABLES_ADMIN privilege (or the deprecated SUPER privilege), you can set the global server time zone value at runtime with this statement:

  • Per-session time zones. Each client that connects has its own session time zone setting, given by the session time_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change its own time zone with this statement:

The session time zone setting affects display and storage of time values that are zone-sensitive. This includes the values displayed by functions such as NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the session time zone to UTC for storage, and from UTC to the session time zone for retrieval.

The session time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns. Nor are values in those data types stored in UTC; the time zone applies for them only when converting from TIMESTAMP values. If you want locale-specific arithmetic for DATE, TIME, or DATETIME values, convert them to UTC, perform the arithmetic, and then convert back.

The current global and session time zone values can be retrieved like this:

timezone values can be given in several formats, none of which are case-sensitive:

  • As the value 'SYSTEM', indicating that the server time zone is the same as the system time zone.

  • As a string indicating an offset from UTC of the form [H]H:MM, prefixed with a + or -, such as '+10:00', '-6:00', or '+05:30'. A leading zero can optionally be used for hours values less than 10; MySQL prepends a leading zero when storing and retriving the value in such cases. MySQL converts '-00:00' or '-0:00' to '+00:00'.

    Prior to MySQL 8.0.19, this value had to be in the range '-12:59' to '+13:00', inclusive; beginning with MySQL 8.0.19, the permitted range is '-13:59' to '+14:00', inclusive.

  • As a named time zone, such as 'Europe/Helsinki', 'US/Eastern', 'MET', or 'UTC'.

    Named time zones can be used only if the time zone information tables in the mysql database have been created and populated. Otherwise, use of a named time zone results in an error:

Several tables in the mysql system schema exist to store time zone information (see The mysql System Schema). The MySQL installation procedure creates the time zone tables, but does not load them. To do so manually, use the following instructions.

Loading the time zone information is not necessarily a one-time operation because the information changes occasionally. When such changes occur, applications that use the old rules become out of date and you may find it necessary to reload the time zone tables to keep the information used by your MySQL server current. See Staying Current with Time Zone Changes.

If your system has its own zoneinfo database (the set of files describing time zones), use the mysql_tzinfo_to_sql program to load the time zone tables. Examples of such systems are Linux, macOS, FreeBSD, and Solaris. One likely location for these files is the /usr/share/zoneinfo directory. If your system has no zoneinfo database, you can use a downloadable package, as described later in this section.

To load the time zone tables from the command line, pass the zoneinfo directory path name to mysql_tzinfo_to_sql and send the output into the mysql program. For example:

The mysql command shown here assumes that you connect to the server using an account such as root that has privileges for modifying tables in the mysql system schema. Adjust the connection parameters as required.

mysql_tzinfo_to_sql reads your system's time zone files and generates SQL statements from them. mysql processes those statements to load the time zone tables.

mysql_tzinfo_to_sql also can be used to load a single time zone file or generate leap second information:

  • To load a single time zone file tz_file that corresponds to a time zone name tz_name, invoke mysql_tzinfo_to_sql like this:

    With this approach, you must execute a separate command to load the time zone file for each named zone that the server needs to know about.

  • If your time zone must account for leap seconds, initialize leap second information like this, where tz_file is the name of your time zone file:

After running mysql_tzinfo_to_sql, restart the server so that it does not continue to use any previously cached time zone data.

If your system has no zoneinfo database (for example, Windows), you can use a package containing SQL statements that is available for download at the MySQL Developer Zone:

Do not use a downloadable time zone package if your system has a zoneinfo database. Use the mysql_tzinfo_to_sql utility instead. Otherwise, you may cause a difference in datetime handling between MySQL and other applications on your system.

To use an SQL-statement time zone package that you have downloaded, unpack it, then load the unpacked file contents into the time zone tables:

Then restart the server.

Do not use a downloadable time zone package that contains MyISAM tables. That is intended for older MySQL versions. MySQL now uses InnoDB for the time zone tables. Trying to replace them with MyISAM tables causes problems.

When time zone rules change, applications that use the old rules become out of date. To stay current, it is necessary to make sure that your system uses current time zone information is used. For MySQL, there are multiple factors to consider in staying current:

  • The operating system time affects the value that the MySQL server uses for times if its time zone is set to SYSTEM. Make sure that your operating system is using the latest time zone information. For most operating systems, the latest update or service pack prepares your system for the time changes. Check the website for your operating system vendor for an update that addresses the time changes.

  • If you replace the system's /etc/localtime time zone file with a version that uses rules differing from those in effect at mysqld startup, restart mysqld so that it uses the updated rules. Otherwise, mysqld might not notice when the system changes its time.

  • If you use named time zones with MySQL, make sure that the time zone tables in the mysql database are up to date:

    • If your system has its own zoneinfo database, reload the MySQL time zone tables whenever the zoneinfo database is updated.

    • For systems that do not have their own zoneinfo database, check the MySQL Developer Zone for updates. When a new update is available, download it and use it to replace the content of your current time zone tables.

    For instructions for both methods, see Populating the Time Zone Tables. mysqld caches time zone information that it looks up, so after updating the time zone tables, restart mysqld to make sure that it does not continue to serve outdated time zone data.

If you are uncertain whether named time zones are available, for use either as the server's time zone setting or by clients that set their own time zone, check whether your time zone tables are empty. The following query determines whether the table that contains time zone names has any rows:

A count of zero indicates that the table is empty. In this case, no applications currently are using named time zones, and you need not update the tables (unless you want to enable named time zone support). A count greater than zero indicates that the table is not empty and that its contents are available to be used for named time zone support. In this case, be sure to reload your time zone tables so that applications that use named time zones can obtain correct query results.

To check whether your MySQL installation is updated properly for a change in Daylight Saving Time rules, use a test like the one following. The example uses values that are appropriate for the 2007 DST 1-hour change that occurs in the United States on March 11 at 2 a.m.

The test uses this query:

The two time values indicate the times at which the DST change occurs, and the use of named time zones requires that the time zone tables be used. The desired result is that both queries return the same result (the input time, converted to the equivalent value in the 'US/Central' time zone).

Before updating the time zone tables, you see an incorrect result like this:

After updating the tables, you should see the correct result:

Leap second values are returned with a time part that ends with :59:59. This means that a function such as NOW() can return the same value for two or three consecutive seconds during the leap second. It remains true that literal temporal values having a time part that ends with :59:60 or :59:61 are considered invalid.

If it is necessary to search for TIMESTAMP values one second before the leap second, anomalous results may be obtained if you use a comparison with 'YYYY-MM-DD hh:mm:ss' values. The following example demonstrates this. It changes the session time zone to UTC so there is no difference between internal TIMESTAMP values (which are in UTC) and displayed values (which have time zone correction applied).

To work around this, you can use a comparison based on the UTC value actually stored in the column, which has the leap second correction applied:

很多童鞋在启动mysql的时候,碰到过这个错误,

首先,澄清一点,出现这个错误的前提是:通过服务脚本来启动mysql。通过mysqld_safe或mysqld启动mysql实例并不会报这个错误。

那么,出现这个错误的原因具体是什么呢?

哈哈,对分析过程不care的童鞋可直接跳到文末的总结部分~

总结

下面,来分析下mysql的服务启动脚本

脚本完整内容如下:

首先,定义相关参数

其中,

basedir 指的二进制压缩包解压后所在的目录,譬如/usr/local/mysql。

datadir 指的是数据目录

service_startup_timeout=900 定义mysql服务启动的时间限制,如果在900s中没有启动成功,则该脚本会退出。

关于/var/lock/subsys,网上的解释如下,后续会用到。

总的来说,系统关闭的过程(发出关闭信号,调用服务自身的进程)中会检查/var/lock/subsys下的文件,逐一关闭每个服务,如果某一运行的服务在/var/lock/subsys下没有相应的选项。在系统关闭的时候,会像杀死普通进程一样杀死这个服务。

通过察看/etc/rc.d/init.d下的脚本,可以发现每个服务自己操纵时都会去查看/var/lock/subsys下相应的服务。

很多程序需要判断是否当前已经有一个实例在运行,这个目录就是让程序判断是否有实例运行的标志,比如说xinetd,如果存在这个文件,表示已经有xinetd在运行了,否则就是没有,当然程序里面还要有相应的判断措施来真正确定是否有实例在运行。通常与该目录配套的还有/var/run目录,用来存放对应实例的PID,如果你写脚本的话,会发现这2个目录结合起来可以很方便的判断出许多服务是否在运行,运行的相关信息等等。

判断basedir和datadir

其中,

mysqld_pid_file_path 指定pid文件的路径

-z string 判断字符串是否为空

如果basedir没有显示设置,则默认为/usr/local/mysql,这也是为什么很多mysql安装教程都推荐将mysql相关文件放到/usr/local/mysql下。

如果datadir没有显示设置,则默认为$basedir/data。

定义log_success_msg()和log_failure_msg()函数

首先,判断/lib/lsb/init-functions文件是否存在,如果存在,则使定义在init-functions文件中的所有shell函数在当前脚本中生效。

如果没有,则定义两个函数,一个用于打印成功日志,一个是打印错误日志。

在RHCS 6.7中,该文件并不存在,已被/etc/init.d/functions所替代。

传递参数

将第一个参数传递给mode,剩下的参数传递给other_args

解析配置文件中的参数

这个函数在脚本后面会涉及到。

主要涉及如下参数:--basedir,--datadir,--pid-file,--service-startup-timeout。

判断my_print_defaults的位置

首先,它判断当前路径下的bin目录中是否存在该可执行文件,如果不存在,则再判断$bindir(通常指的是$basedir/bin)目录下是否存在。

如果还是没有,则会判断/etc/my.cnf是否存在并且可读,如果是,则判断该配置文件中是否指定了basedir参数,

如果指定了,则取出该参数的值,并判断该值对应的目录中是否存在bin/my_print_defaults可执行文件

最后一步,如果在上述目录中实在没发现my_print_defaults文件,

索性就将print_defaults设置为'my_print_defaults',寄希望于该命令在当前的PATH环境中。

查找默认的配置文件

-r file 如果文件可读,则为真

解析配置文件中的参数

my_print_defaults的用法如下:

my_print_defaults --defaults-file=example.cnf client mysql

即读取配置文件中,client和mysql部分的参数配置,

具体在本脚本中,是读取mysqld,server,mysql_server,mysql.server四个部分的配置参数。

设置pid file的路径

-z string 判断字符串是否为空

如果--pid-file没有在读取到的配置文件中设置或者脚本刚开始的mysqld_pid_file_path参数没有设置,

则pid file默认设置在datadir下,以主机名.pid命名。

如果该参数设置了,还需要进一步判断

如果该参数中带有斜杠,则代表给定的值带有路径,可直接使用。

如果该参数中没带路径,则代表给定的值只是pid的文件名,可将其设在datadir下。

服务脚本start选项

首先,切换到$basedir中

其次,判断$basedir/bin中的mysqld_safe是否是可执行文件,如果是,则启动mysqld实例,如果不是,则报错退出。

那么,启动流程又是如何实现的呢?

首先,执行$bindir/mysqld_safe --datadir='$datadir' --pid-file='$mysqld_pid_file_path' $other_args >/dev/null 2>&1 &命令,启动mysqld实例。

注意到没有,mysqld_safe其实是在basedir中执行的,包括mysql初始化脚本mysql_install_db,也建议在basedir中执行,具体可参考:

分析MariaDB初始化脚本mysql_install_db

然后通过wait_for_pid函数进行判断,具体可见下文对于wait_for_pid函数的分析

判断完毕后,

查看$lockdir目录是否可写,可写的话,则在目录上创建一个文件。

wait_for_pid函数

在利用mysqld_safe启动mysql实例后,会调用该参数

Mysql Servertimezone Asia Shanghai

其中$!在shell中用于获取最后运行的后台Process的PID,具体在本例中,是mysqld_safe进程的pid。

因为第一个参数是created,所以会执行test -s '$pid_file_path' && i=' && break命令。

-s file 如果文件的长度不为零,则为真

该命令的意思是如果pid文件存在,则将变量i设置为空,并退出while循环。

然后执行如下判断,

如果$i为空,则打印成功日志,并退出脚本,很显然,在pid文件存在的情况下,会将变量i设置为空。

再来看看pid文件不存在的情况

首先,会判断$pid是否不为空(即if test -n '$pid')

如果不为空,则代表在执行完mysqld_safe后,已经捕捉到了该进程的pid。

在这种情况下,进一步通过kill -0 '$pid'确认该进程是否存在。

kill -0就是不发送任何信号,但是系统会进行错误检查,所以经常用来检查一个进程是否存在,当进程不存在时, kill -0 pid会返回错误

如果该进程存在,则不执行任何操作,直接跳到如下操作

将变量i加1,并sleep 1s。

然后,继续while循环,之所以这样做,是考虑到mysqld_safe已经执行,但是mysqld实例还在启动过程中,还没创建好pid文件。

一直到$1达到$service_startup_timeout定义的时长。

如果在while循环的过程中,通过kill -0 '$pid'判断到进程已经不存在了,

则会再判断一次,如果这次判断的结果依旧是pid file不存在,且进程不存在,则会执行

这就是大名鼎鼎的“The server quit without updating PID file”的由来。

服务脚本stop选项

首先,判断pid文件的长度是否不为零。

-s file 如果文件的长度不为零,则为真

此时,会通过pid文件获取mysqld进程的pid,注意,不是mysqld_safe进程的pid

然后,判断mysqld进程是否在正常运行,

Servertimezone

如果是,则通过kill $mysqld_pid的方式来关闭mysqld进程

杀死进程最安全的方法是单纯使用kill命令,不加修饰符,不带标志。

标准的kill命令通常会终止有问题的进程,并把进程的资源释放给系统。然而,如果进程启动了子进程,只杀死父进程,子进程仍在运行,因此仍消耗资源。为了防止这些所谓的“僵尸进程”,应确保在杀死父进程之前,先杀死其所有的子进程。

然后,调用wait_for_pid函数进行判断,其实,wait_for_pid函数中设置avoid_race_condition变量的目的是为了stop选项,确实有可能出现,mysqld是在检查pid file之后,检查进程是否存活之前退出的。

如果mysqld进程没有正常运行,在会打印“MySQL server process #$mysqld_pid is not running!”信息,并删除pid文件。

如果在执行stop的时候,判断pid文件的长度为0,则会打印'MySQL server PID file could not be found!'信息。

所以,在pid文件不存在的情况下,通过服务脚本执行stop选项并不会关闭mysqld进程,这个时候,就可通过kill $mysqld_pid的方式来关闭mysqld进程。

服务脚本restart选项

首先,先执行stop操作,如果stop操作成功的话,则继续执行start操作。

如果stop操作失败的话,则会输出'Failed to stop running server, so refusing to try to start.'信息,并退出脚本。

服务脚本reload选项

首先,判断pid文件的长度是否为0,如果不为0,则将该文件中的值设置为mysqld_pid变量的值。

然后对该进程执行kill -HUP操作。

pid 是进程标识。如果想要更改配置而不需停止并重新启动服务,请使用该命令。在对配置文件作必要的更改后,发出该命令以动态更新服务配置。

根据约定,当您发送一个挂起信号(信号 1 或 HUP)时,大多数服务器进程(所有常用的进程)都会进行复位操作并重新加载它们的配置文件。

如果pid文件的长度为0,则输出'MySQL PID file could not be found!'。

服务脚本status选项

首先,判断pid文件长度是否为0,如果不是,则读取该文件中的值,并判断pid对应的进程是否运行正常,

如果运行正常,则输出'MySQL running'

如果不正常,则输出'MySQL is not running, but PID file exists'

如果pid文件的长度为0,则试图通过mysqld的启动命令来获取其pid,

这个时候,可能存在一个mysqld程序启动了多个实例,这会导致pid_count=`echo $mysqld_pid | wc -w`大于1。

这个时候,会输出'Multiple MySQL running but PID file could not be found'信息,并退出脚本。

如果mysqld_pid为空,则会继续判断'$lock_file_path'是否存在,如果存在,

则会输出'MySQL is not running, but lock file ($lock_file_path) exists'信息。

如果'$lock_file_path'不存在,则会输出'MySQL is not running'信息。

如果mysqld_pid等于1,则会输出'MySQL is running but PID file could not be found'信息。

服务脚本其它选项

如果脚本的第一个参数不是上述几个选项,则会输出Usage信息。

至此,mysql的服务脚本分析完毕~

总结

在通过服务脚本启动mysql的过程中,报“The server quit without updating PID file”错误,有两个条件

首先,pid文件不存在

其次,通过kill -0 $pid检查到进程并不存在

Mysql Servertimezone Utc+8

这个时候,只能通过mysql数据库的错误日志来定位。

服务脚本如果不做任何调整的话,默认的basedir是/usr/local/mysql,datadir是/usr/local/mysql/data

如果自己的mysql服务均不是默认路径,

则需要在该脚本中显式设置

经测试,需设置如下几处:

1. 设置basedir和添加conf变量

其中,conf指的是mysqld的配置文件,建议配置文件中显式指定basedir和datadir的值。

在这里,datadir可不设置,因为datadir可通过配置文件来获取。

但是basedir必须要指定,因为要首先根据basedir来判断my_print_deefauts命令

2. 第256行,添加extra_args=' -c $conf'

3. 修改285行mysqld_safe的启动参数

修改为,

主要是添加了--defaults-file选项

Jdbc Mysql Servertimezone

以上所述是小编给大家介绍的深度解析MySQL启动时报“The server quit without updating PID file”错误的原因,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!