Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable explicit_defaults_for_timestamp?

Tags:

mysql

When I try to start my mySQL server I get message:

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

I find answer on:
http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp

But how to enable it? Where?

like image 559
Mike Anderson Avatar asked Mar 29 '13 10:03

Mike Anderson


People also ask

How do I permanently set a global variable in MySQL?

To persist a global system variable to the mysqld-auto. cnf option file in the data directory, precede the variable name by the PERSIST keyword or the @@PERSIST. qualifier: SET PERSIST max_connections = 1000; SET @@PERSIST.

How do I change a read only variable in MySQL?

The innodb_ft_min_token_size is not a dynamic variable so you will have to change the config file my. cnf and add innodb_ft_min_token_size=6 . Alternatively you need to change the startup command of your MySQL server. After the change you must restart your MySQL server.

How do I create a variable in MySQL?

MySQL provides a SET and SELECT statement to declare and initialize a variable. The user-defined variable name starts with @ symbol. The user-defined variables are not case-sensitive such as @name and @NAME; both are the same. A user-defined variable declares by one person cannot visible to another person.


2 Answers

First you don't need to change anything yet.

Those nonstandard behaviors remain the default for TIMESTAMP but as of MySQL 5.6.6 are deprecated and this warning appears at startup

Now if you want to move to new behaviors you have to add this line in your my.cnf in the [mysqld] section.

explicit_defaults_for_timestamp = 1 

The location of my.cnf (or other config files) vary from one system to another. If you can't find it refer to https://dev.mysql.com/doc/refman/5.7/en/option-files.html

like image 146
gagarine Avatar answered Sep 18 '22 17:09

gagarine


In your mysql command line do the following:

mysql> SHOW GLOBAL VARIABLES LIKE '%timestamp%'; +---------------------------------+-------+ | Variable_name                   | Value | +---------------------------------+-------+ | explicit_defaults_for_timestamp | OFF   | | log_timestamps                  | UTC   | +---------------------------------+-------+ 2 rows in set (0.01 sec)  mysql> SET GLOBAL explicit_defaults_for_timestamp = 1; Query OK, 0 rows affected (0.00 sec)  mysql> SHOW GLOBAL VARIABLES LIKE '%timestamp%'; +---------------------------------+-------+ | Variable_name                   | Value | +---------------------------------+-------+ | explicit_defaults_for_timestamp | ON    | | log_timestamps                  | UTC   | +---------------------------------+-------+ 2 rows in set (0.00 sec) 
like image 42
Prasanna Avatar answered Sep 20 '22 17:09

Prasanna