大网数据广告活动
服务器运维问答

Keep MySQL strict mode disabled after server restart (Hostinger VPS with Ubuntu 18.04)

· 52CE 我爱测

So I have a site hosted on VPS Hosting Plan 2 of Hostinger, and it uses MySQL for the database, with the OS of my Virtual Machine being Ubuntu 18.04. I have to keep MySQL's strict mode disabled globally the entire time for some p…

问题原文

原帖链接 · Syed M. Sannan · CC BY-SA 4.0

So I have a site hosted on VPS Hosting Plan 2 of Hostinger, and it uses MySQL for the database, with the OS of my Virtual Machine being Ubuntu 18.04.

I have to keep MySQL's strict mode disabled globally the entire time for some parts of the site to work. For context, I am only managing the server end at the moment, so I cannot fix the parts of this site that require me to disable strict mode. Those fixes are on the developers' end, and they'll eventually handle them at some point.

Now, the problem I am facing is that when I disable strict mode, it automatically gets enabled after several hours (or a day). This is due to the scheduled server restarts that Hostinger's VPS servers seem to have. Whenever the server restarts, MySQL's strict mode gets re-enabled.

How can I do it so that strict mode is permanently disabled until I turn it back on myself? I obviously don't want to be turning it on every few hours... :)

Edit: I currently used set global sql_mode=''; to disable MySQL strict mode.

已采纳解答

原帖链接 · Rachel · CC BY-SA 4.0

If you disable mysql strict mode using below command, it will get revert after the server restart.

set global sql_mode='';

To set/disable it permanently, you have to edit the value in mysql conf file.

/etc/mysql/my.cnf or /etc/my.cnf based on your OS.

Find the following line:

sql_mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

Replace it with the line below: If the line is not found, insert the line under the [mysqld] section (if there is no [mysqld] section, pls create it).

[mysqld] 
sql_mode= ""

Restart the MySQL service for the change to take effect.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-11-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。