Loading...

MySQL:ERROR_1067

Temperature: 0 °C

Mark ChangMark Chang
author_tools

最近安裝了Ubuntu Server 18.04系統。
接著安裝了MySQL 5.7.21的版本。
在時間的預設值上發生了ERROR 1067 的錯誤警告。
原因是因為MySQL 5.7.21的版本默認的預設值是不允許時間欄位為0000-00-00 00:00:00。
如下:

mysql> show variables like 'sql_mode';

當執行上述指令時得到的結果如下
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

上頭顯示了NO_ZERO_IN_DATE,NO_ZERO_DATE的部分就是時間欄位預設不能為0。
解決方式,需要修改全局變量sql_mode,去掉NO_ZERO_IN_DATE,NO_ZERO_DATE。
如下:
mysql> set global sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

但是上列方式只適用於當前的生效,意思就是說若是重新啟動Mysql服務就會失效。
若要永久生效則必須在Mysql的安裝目錄底下my.cnf裡新增以下參數
 [mysqld]sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

之後重啟Mysql。

以上紀錄



 

https://innstory.com/story-MySQL:ERROR1067-2640
Mysql

Prev
 Linux底下查看Mysql版本

Next
分享_人事動盪!近400天GoogleCloud旅程告終台灣區總經理邵光華低調卸任|數位時代 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

  • guest

    訪客 2021-02-24 11:14:48 1

    技術文必須給讚
    • guest

      chung 2021-06-14 22:18:58 0

      TO:訪客
      回台灣了?

Recommended reading

Author's other related stories

要如何知道ajax執行失敗原因?

要如何知道ajax執行失敗原...

只要在error的function 更改為以下寫法即可: error: function (XMLH...

使用PHP mb_substr() 函式,擷取部分字串並記得使用UTF-8。

使用PHP mb_subst...

pexelsphotohello5 文字長度太長,一般來說我們可以使用DIV包住字串,再定義DIV的...

PDO常用方法

pexelsphoto555.jpeg PDO::query() 主要用於有記錄結果返回的操作(PD...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format