简体   繁体   English

如何使 sql-mode="NO_ENGINE_SUBSTITUTION" 在 MySQL my.cnf 中永久存在

[英]How to make sql-mode=“NO_ENGINE_SUBSTITUTION” permanent in MySQL my.cnf

UPDATE FIXED 1/18/15更新已于 15 年 1 月 18 日修复

After we recently updated to MySQL 5.6.27 (from the Ubuntu repo), this option now works.在我们最近更新到 MySQL 5.6.27(来自 Ubuntu 存储库)之后,这个选项现在可以工作了。 So this appears to have been a problem with the previous version of MySQL.所以这似乎是以前版本的 MySQL 的问题。

ORIGINAL QUESTION原问题

With a new upgrade to MySQL (5.6.20), updates and inserts fail unless I set sql-mode to NO_ENGINE_SUBSTITUTION.在对 MySQL (5.6.20) 进行新升级后,除非我将 sql-mode 设置为 NO_ENGINE_SUBSTITUTION,否则更新和插入都会失败。

Thanks to the documentation , I can run the following from mysql terminal and that fixes the problem (temporarily):感谢文档,我可以从 mysql 终端运行以下命令并解决问题(暂时):

SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';`

But the next time MySQL restarts, these settings are lost.但是下次 MySQL 重新启动时,这些设置就会丢失。

So I have tried to make that permanent by editing /etc/mysql/my.cnf (on my standard server running Ubuntu 12.04.5 LTS), and adding the config settings that the documentation says should be added:所以我试图通过编辑 /etc/mysql/my.cnf(在我运行 Ubuntu 12.04.5 LTS 的标准服务器上)并添加文档中说应该添加的配置设置来使其永久化:

[mysqld]
sql-mode="NO_ENGINE_SUBSTITUTION"

Alternative Syntaxes for Testing用于测试的替代语法

Just for testing purposes, I have also tried the following formats (which do not cause errors when restarting MySQL, but they do not affect the setting).只是为了测试,我还尝试了以下格式(重启MySQL时不会出错,但不影响设置)。

# dash no quotes
sql-mode=NO_ENGINE_SUBSTITUTION
# underscore no quotes
sql_mode=NO_ENGINE_SUBSTITUTION
# underscore and quotes
sql_mode="NO_ENGINE_SUBSTITUTION"

Nothing works.什么都行不通。 After restart this setting is lost and I have to run the commands manually again from mysql terminal to make saving work again.重新启动后,此设置丢失,我必须再次从 mysql 终端手动运行命令才能再次保存。

Alternative Locations替代地点

  • I know /etc/mysql/my.cnf is being referenced because we have replication defined in this file, and that is working.我知道 /etc/mysql/my.cnf 正在被引用,因为我们在此文件中定义了复制,并且正在运行。
  • There is not another identical setting in this file that is overwriting it.此文件中没有其他相同的设置会覆盖它。

I get a list of the config files that are being referenced by running this from the command line:通过从命令行运行它,我得到了被引用的配置文件的列表:

mysqld --help --verbose

I see a line that reads:我看到一行写着:

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 

This is the default location it "looks" for files, it doesn't mean that it actually found a file there, eg my server doesn't have /etc/my.cnf , /usr/etc/my.cnf or ~/.my.cnf .这是它“查找”文件的默认位置,这并不意味着它实际上在那里找到了一个文件,例如我的服务器没有/etc/my.cnf/usr/etc/my.cnf~/.my.cnf

So it looks like my config in /etc/mysql/my.cnf is the only file mysql is referencing, and therefore this setting is not being overwritten.所以看起来我在 /etc/mysql/my.cnf 中的配置是 mysql 引用的唯一文件,因此这个设置不会被覆盖。

Logical Conclusion of Testing测试的逻辑结论

Logically then, it seems the syntax is not correct or is being ignored for some other reason.从逻辑上讲,语法似乎不正确或由于其他原因被忽略。 Any other ideas?还有其他想法吗?

Just to add my configuration to the mix, I'm using MySQL 5.7.8 which has the same strict sql_mode rules by default.只是为了将我的配置添加到组合中,我使用的是 MySQL 5.7.8,默认情况下它具有相同的严格 sql_mode 规则。

  • I finally figured the following working in my /etc/mysql/my.conf:我终于在我的 /etc/mysql/my.conf 中找到了以下工作:

     [mysqld] sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"

ie dash, not underscore and quotes around the value.即破折号,而不是下划线和值周围的引号。

  • I have NO other my.conf files other than /etc/mysql/my.conf除了 /etc/mysql/my.conf 之外,我没有其他 my.conf 文件

  • There are some extra config includes being loaded from /etc/mysql/conf.d/ but they are blank.有一些额外的配置包括从 /etc/mysql/conf.d/ 加载,但它们是空白的。

And that seems to work for me.这似乎对我有用。

Your server may read a different my.cnf than the one you're editing (unless you specified it when starting mysqld).您的服务器读取的my.cnf可能与您正在编辑的不同(除非您在启动 mysqld 时指定了它)。

From the MySQL Certification Study Guide :来自MySQL 认证学习指南

The search order includes two general option files, /etc/my.cnf and $MYSQL_HOME/my.cnf .搜索顺序包括两个通用选项文件, /etc/my.cnf$MYSQL_HOME/my.cnf The second file is used only if the MYSQL_HOME environment variable is set.仅当设置了MYSQL_HOME环境变量时才使用第二个文件。 Typically, you seet it to the MySQL installation directory.通常,您将其设置为 MySQL 安装目录。 (The mysqld_safe script attempts to set MYSQL_HOME if it is not set before starting the server.) The option file search order also includes ~/.my.cnf (that is the home directory). (如果在启动服务器之前没有设置MYSQL_HOME ,mysqld_safe 脚本会尝试设置它。)选项文件搜索顺序还包括~/.my.cnf (即主目录)。 This isn't an especially suitable location for server options.这不是服务器选项特别合适的位置。 (Normally, you invoke the server as mysql , or as root with a --user=mysql option. The user-specific file read by the server would depend on which login account you invoke it from, possibly leading to inconsistent sets of options being used.) (通常,您以mysqlroot身份调用服务器并使用--user=mysql选项。服务器读取的特定于用户的文件将取决于您从哪个登录帐户调用它,这可能会导致选项集不一致用过的。)

Another possibility is of course, that your sql-mode option gets overwritten further down in the same file.当然,另一种可能性是,您的sql-mode选项在同一文件中被进一步覆盖。 Multiple options have to be separated by , in the same line.多个选项必须在同一行中用,分隔。

PS: And you need the quotes, IIRC. PS:你需要引号,IIRC。 Now that you've tried it without quotes, I'm pretty sure, you're editing the wrong file, since MySQL doesn't start when there's an error in the option file.现在你已经尝试了它没有引号,我很确定,你正在编辑错误的文件,因为在选项文件中没有错误时,MySQL不会启动。

PPS: Had a look at my config files again, there it's PPS:再次查看我的配置文件,它在那里

[mysqld]
sql_mode = "NO_ENGINE_SUBSTITUTION"

and it's working.它正在工作。

It should be:它应该是:

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

instead of代替

[mysqld]
sql_mode="NO_ENGINE_SUBSTITUTION"

then restart mysqld service.然后重启mysqld服务。

Woks fine for me on ubuntu 16.04.在 ubuntu 16.04 上对我来说很好。 path: /etc/mysql/mysql.cnf路径:/etc/mysql/mysql.cnf

and paste that并粘贴

[mysqld]
#
# * Basic Settings
#
sql_mode = "NO_ENGINE_SUBSTITUTION"

For me it was a permission problem.对我来说,这是一个许可问题。

enter:进入:

mysqld --verbose --help | grep -A 1 "Default options"

[Warning] World-writable config file '/etc/mysql/my.cnf' is ignored. [警告] 世界可写的配置文件 '/etc/mysql/my.cnf' 被忽略。

So try to execute the following, and then restart the server于是尝试执行以下,然后重启服务器

chmod 644 '/etc/mysql/my.cnf'

It will give mysql access to read and write to the file.它将授予 mysql 读取和写入文件的权限。

On Linux Mint 18 the default config file that has the sql-mode option set is located here :Linux Mint 18 上,设置了sql-mode选项的默认配置文件位于此处:

/usr/my.cnf

And relevant line is:相关行是:

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

So You can set there.所以你可以在那里设置。

If not sure what config file has such option You can search for it:如果不确定哪个配置文件有这样的选项您可以搜索它:

$ sudo find / -iname "*my.cnf*"

And get a list:并得到一个列表:

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

My problem was that I had spaces in between the options on 5.7.20.我的问题是我在 5.7.20 的选项之间有空格。 Removing them so the line looked like删除它们,使线条看起来像

[mysqld]
sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

The solution is pretty easy... Searched for it for a while and it turns out that you just have to edit 2 config-files:解决方案很简单......搜索了一段时间,结果你只需要编辑2个配置文件:

  • /usr/my.cnf
  • /etc/mysql/my.cnf

in both files you'll have to add:在这两个文件中,您必须添加:

[mysqld]
...
sql_mode=NO_ENGINE_SUBSTITUTION

At least, that's what's working for 5.6.24-2+deb.sury.org~precise+2至少,这适用于 5.6.24-2+deb.sury.org~precise+2

For me both keys for sql-mode worked.对我来说, sql-mode两个有效。 Whether I used我是否使用过

# dash no quotes
sql-mode=NO_ENGINE_SUBSTITUTION

or或者

# underscore no quotes
sql_mode=NO_ENGINE_SUBSTITUTION

in the my.ini file made no difference and both were accepted, as far as I could test it.my.ini文件中没有任何区别,两者都被接受,就我可以测试而言。

What actually made a difference was a missing newline at the end of the my.ini file.实际上有所不同的是my.ini文件末尾缺少换行符

So everyone having problems with this or similar problems with my.ini / my.cnf : Make sure there is a blank line at the end of the file!所以每个人都遇到这个问题或my.ini / my.cnf类似问题:确保文件末尾有一个空行!

Tested using MySQL 5.7.27.使用 MySQL 5.7.27 测试。

If you're using mariadb, you have to modify the mariadb.cnf file located in /etc/mysql/conf.d/.如果您使用的是 mariadb,则必须修改位于 /etc/mysql/conf.d/ 中的 mariadb.cnf 文件。

I supposed the stuff is the same for any other my-sql based solutions.我想这些东西对于任何其他基于 mysql 的解决方案都是一样的。

I am running WHM 10.2.15-MariaDB.我正在运行 WHM 10.2.15-MariaDB。 To permanently disable strict mode first find out which configuration file our installation prefers.要永久禁用严格模式,首先要找出我们的安装更喜欢哪个配置文件。 For that, we need the binary's location:为此,我们需要二进制文件的位置:

$ which mysqld
/usr/sbin/mysqld

Then, we use this path to execute the lookup:然后,我们使用此路径执行查找:

$ /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"

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

We can see that the first favored configuration file is one in the root of the etc folder but that there is a second .cnf file hidden - ~/.my.cnf.我们可以看到第一个偏好的配置文件位于 etc 文件夹的根目录中,但隐藏了第二个 .cnf 文件 - ~/.my.cnf。 Adding the following to the ~/.my.cnf file permanently disabled strict mode for me (needs to be within the mysqld section):将以下内容添加到 ~/.my.cnf 文件永久禁用了我的严格模式(需要在 mysqld 部分中):

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION

I found that adding the line to /etc/my.cnf had no effect at all apart from sending me crazy.我发现将这一行添加到 /etc/my.cnf 除了让我发疯之外根本没有任何影响。

It was making me crazy also until I realized that the paragraph where the key must be is [mysqld] not [mysql]这也让我发疯,直到我意识到关键所在的段落是 [mysqld] 而不是 [mysql]

So, for 10.3.22-MariaDB-1ubuntu1, my solution is, in /etc/mysql/conf.d/mysql.cnf所以,对于 10.3.22-MariaDB-1ubuntu1,我的解决方案是,在 /etc/mysql/conf.d/mysql.cnf

[mysqld]
sql_mode = "ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

[Fixed] Server version: 10.1.38-MariaDB - mariadb.org binary distribution [已修复] 服务器版本:10.1.38-MariaDB - mariadb.org 二进制分发

Go to: C:\\xampp\\mysql\\bin open my.ini in notepad and find [mysqld] (line number 27) then after this line(line no 28) just type: skip-grant-tables转到:C:\\xampp\\mysql\\bin 在记事本中打开 my.ini 并找到 [mysqld](第 27 行)然后在此行(第 28 行)之后输入:skip-grant-tables

save the file and then reload the phpmyadmin page.It worked for me.保存文件,然后重新加载 phpmyadmin 页面。它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM