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

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

JavaScript 搜尋字串並取代

JavaScript 搜尋字串並取代

在 JavaScript 做搜尋並取代字串可以使用 replace() replace...

Android 禁止螢幕旋轉

Android 禁止螢幕旋轉

首先找到AndroidManifest.xml檔案 位置在app/manifests/...

破版,很醜!!

破版,很醜!!

pexelsphotowrite 破版......很醜對不對!! 我想這是所有從事網頁...

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