Mysql

MySQL 5.7.15 關閉嚴格模式

  • April 29, 2017

mysql Ver 14.14 Distrib 5.7.15,適用於使用 EditLine 包裝器的 Linux (x86_64)

我正在嘗試配置我的 MYSQL 實例以關閉我目前所做的一些更嚴格的設置:

  mysql> select @@GLOBAL.sql_mode;
   +-------------------------------------------------------------------------------------------------------------------------------------------+
   | @@GLOBAL.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 |

須藤 vi /etc/mysql/mysql.cnf

[mysqld]
sql-mode=""

mysqld重啟。然後嘗試看看全域SQL模式是什麼:

mysql> select @@GLOBAL.sql_mode;
       +-------------------------------------------------------------------------------------------------------------------------------------------+
       | @@GLOBAL.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 |

任何人對下一步嘗試什麼有任何想法。似乎無法永久保留此設置,也看不到要嘗試的任何其他文件。

編輯:定位返回:

/etc/alternatives/my.cnf
/etc/mysql/my.cnf
/etc/mysql/my.cnf.fallback
/var/lib/dpkg/alternatives/my.cnf

預設選項按給定順序從以下文件中讀取: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

Aug 05, 2015,我在升級到 MySQL 5.6 後回復了文章Set sql_mode “blank”

在我的回答中,我解釋了 Oracle 如何創建一個額外的my.cnf名為/usr/my/cnf.

它有這個(請記住這是我當時正在回答的 MySQL 5.6)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

我猜一些開發人員只是放棄了將其放入程式碼中,而是將配置文件作為一些瘋狂的快捷方式。

如果你有這樣的文件,請把最後一行註釋掉,然後重啟mysqld。

MySQL 5.7 的預設值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

更新 2017-04-27 17:23 EDT

我剛跑mysqld --help --verbose | head -13就得到了這個

$ mysqld --help --verbose | head -13
2017-04-27T21:17:13.237941Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-04-27T21:17:13.238060Z 0 [Warning] Changed limits: max_connections: 214 (requested 500)
2017-04-27T21:17:13.238065Z 0 [Warning] Changed limits: table_open_cache: 400 (requested 2048)
mysqld  Ver 5.7.17-log for Linux on x86_64 (MySQL Community Server (GPL))
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Starts the MySQL database server.

Usage: mysqld [OPTIONS]

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

請執行mysqld --help --verbose 2>/dev/null | head -13 | tail -1

檢查提到的每個文件

更新 2017-04-29 19:03 EDT

我在升級到 MySQL 5.6 後在 Set sql_mode “blank”/usr/my.cnf中提到的技巧來自Morgan Tocker 在“MySQL 5.6 的變化”標題下寫的一篇文章這種sql_mode的誘餌和切換方法可能不適用於這種情況,因為這是 MySQL 5.7。

正如我在之前的評論中提到的,我已經成功地添加了sql_mode/etc/my.cnf

[mysqld]
sql_mode=''

您不必重新啟動 mysqld。你登錄到mysql並執行

SET GLOBAL sql_mode='';
SELECT @@GLOBAL.sql_mode;

這會將傳入連接設置為空白sql_mode

這不會改變目前建立的連接的sql_mode

重新啟動 mysqld 將保證所有傳入連接都將其設為空白。

如果您無法重新啟動 mysqld,則必須重新啟動您的應用程序/Web 伺服器並使其斷開連接。然後,重新啟動您的應用程序/Web 伺服器以建立連接。

請試試這個,讓我們看看結果。

引用自:https://dba.stackexchange.com/questions/172211