我想将默认的sql_mode更改为:
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
所以我把它设置在etc/mysql/mysql.conf.d/mysqld.cnf
:
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUT>
sort_buffer_size=10M
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
但是当我重新启动MySQL时,我得到以下错误:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-01-27 16:32:39 EET; 9s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 55142 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, sta>
Process: 55181 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Main PID: 55181 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 2 (No such file or directory)
我已经看了关于这个主题的所有教程,但似乎有些东西已经改变了。
我需要一个永久的解决方案,因为现在,每次重新启动时,以下设置都会消失。
mysql > SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
我该如何解决这个问题?
正如这个答案所述,NO_AUTO_CREATE_USER模式在MySQL 8中被删除(假设这是你在Ubuntu 20中使用的版本),如果包含在你的配置中,将导致错误。
删除它应该修复你的错误。因此,要添加到cnf文件中的行应该是:
[mysqld]
sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION