如何在 localhost (xampp) 中打开/关闭 MySQL 严格模式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40881773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:05:31  来源:igfitidea点击:

How to turn on/off MySQL strict mode in localhost (xampp)?

mysqlxampplocalhostmariadbmariasql

提问by Ipsita Rout

I want to know how to check whether MySQL strict mode is on or off in localhost(xampp).

我想知道如何在 localhost(xampp) 中检查 MySQL 严格模式是打开还是关闭。

If on then for what modes and how to off.

如果打开,那么什么模式以及如何关闭。

If off then how to on.

关了怎么开。

I already followed http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-fulland https://mariadb.com/kb/en/mariadb/sql_mode/and other related sites too. But I didn't get an exact answer for my question.

我已经关注了http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-fullhttps://mariadb.com/kb/en/mariadb/sql_mode/和其他相关网站也是如此。但我没有得到我的问题的确切答案。

回答by Ipsita Rout

->STRICT_TRANS_TABLESis responsible for setting MySQL strict mode.

-> STRICT_TRANS_TABLES负责设置 MySQL 严格模式。

->To checkwhether strict mode is enabled or not run the below sql:

->要检查是否启用了严格模式,请运行以下 sql:

SHOW VARIABLES LIKE 'sql_mode';

If one of the value is STRICT_TRANS_TABLES, then strict mode is enabled, else not. In my case it gave

如果值之一是STRICT_TRANS_TABLES,则启用严格模式,否则不启用。就我而言,它给了

+--------------+------------------------------------------+ 
|Variable_name |Value                                     |
+--------------+------------------------------------------+
|sql_mode      |STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION|
+--------------+------------------------------------------+

Hence strict mode is enabledin my case as one of the value is STRICT_TRANS_TABLES.

因此,在我的情况下启用了严格模式,因为其中一个值是STRICT_TRANS_TABLES

->To disablestrict mode run the below sql:

->要禁用严格模式,请运行以下 sql:

set global sql_mode='';

[or any mode except STRICT_TRANS_TABLES. Ex: set global sql_mode='NO_ENGINE_SUBSTITUTION';]

[或除 STRICT_TRANS_TABLES 之外的任何模式。例如:设置全局 sql_mode='NO_ENGINE_SUBSTITUTION';]

->To again enablestrict mode run the below sql:

->要再次启用严格模式,请运行以下 sql:

set global sql_mode='STRICT_TRANS_TABLES';

回答by DragonFire

To Change it permanentlyin ubuntu do the following

要在 ubuntu 中永久更改它,请执行以下操作

in the ubuntu command line

在 ubuntu 命令行中

sudo nano /etc/mysql/my.cnf

Then add the following

然后添加以下内容

[mysqld]
sql_mode=

回答by Kasumi Gunasekara

First, check whether the strict mode is enabled or not in mysql using:

首先,使用以下命令检查mysql中是否启用了严格模式:

     SHOW VARIABLES LIKE 'sql_mode';

If you want to disable it:

如果你想禁用它:

     SET sql_mode = '';

or any other mode can be set except the following. To enable strict mode:

或者可以设置除以下以外的任何其他模式。要启用严格模式:

     SET sql_mode = 'STRICT_TRANS_TABLES';

You can check the result from the first mysql query.

您可以检查第一个 mysql 查询的结果。

回答by Toundrake

Check the value with

检查值

SELECT @@GLOBAL.sql_mode;

then clear the @@global.sql_mode by using this command:

然后使用以下命令清除@@global.sql_mode:

SET @@GLOBAL.sql_mode=''

回答by FreeText

To change it permanently in Windows (10), edit the my.inifile. To find the my.ini file, look at the path in the Windows server. E.g. for my MySQL 5.7 instance, the service is MYSQL57, and in this service's properties the Path to executable is:

要在 Windows (10) 中永久更改它,请编辑my.ini文件。要查找 my.ini 文件,请查看 Windows 服务器中的路径。例如,对于我的 MySQL 5.7 实例,该服务是MYSQL57,并且在该服务的属性中,可执行文件的路径是:

"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" MySQL57

"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" MySQL57

I.e. edit the my.inifile in C:\ProgramData\MySQL\MySQL Server 5.7\. Note that C:\ProgramData\is a hidden folder in Windows (10). My file has the following lines of interest:

my.iniC:\ProgramData\MySQL\MySQL Server 5.7\. 请注意,这C:\ProgramData\是 Windows (10) 中的隐藏文件夹。我的文件有以下感兴趣的行:

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

Remove STRICT_TRANS_TABLES,from this sql-mode line, save the file and restart the MYSQL57 service. Verify the result by executing SHOW VARIABLES LIKE 'sql_mode';in a (new) MySQL Command Line Client window.

STRICT_TRANS_TABLES,从此 sql-mode 行中删除,保存文件并重新启动 MYSQL57 服务。通过SHOW VARIABLES LIKE 'sql_mode';在(新的)MySQL 命令行客户端窗口中执行来验证结果。

(I found the other answers and documents on the web useful, but none of them seem to tell you where to find the my.ini file in Windows.)

(我发现网上的其他答案和文档很有用,但它们似乎都没有告诉您在 Windows 中在哪里可以找到 my.ini 文件。)

回答by Khoa tr?n ??ng

In my case, I need to add:

就我而言,我需要添加:

sql_mode="STRICT_TRANS_TABLES"

under [mysqld]in the file my.inilocated in C:\xampp\mysql\bin.

[mysqld]该文件中my.ini位于C:\xampp\mysql\bin

回答by Eric Korolev

You can check the local and global value of it with:

您可以使用以下命令检查它的本地和全局值:

SELECT @@SQL_MODE, @@GLOBAL.SQL_MODE;

回答by MocXi

on Debian 10 I start mysql from ./opt/lampp/xampp start

在 Debian 10 上,我从 ./opt/lampp/xampp start

I do strace ./opt/lampp/sbin/mysqldand see that my.cnf is there:

我确实strace ./opt/lampp/sbin/mysqld看到了 my.cnf 在那里:

stat("/opt/lampp/etc/my.cnf", {st_mode=S_IFREG|0644, st_size=5050, ...}) = 0
openat(AT_FDCWD, "/opt/lampp/etc/my.cnf", O_RDONLY|O_CLOEXEC) = 3

hence, I add sql_mode config to /opt/lampp/etc/my.cnfinstead of /etc/mysql/my.cnf

因此,我将 sql_mode 配置添加到/opt/lampp/etc/my.cnf而不是/etc/mysql/my.cnf