如何修复"变量'sql_mode'不能设置为'NULL'的值"错误

mar*_*zzz 5 mysql

我有这张桌子:

# Dumping structure for table editz.to_import
CREATE TABLE IF NOT EXISTS `to_import` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `reference` int(11) unsigned NOT NULL,
  `trackid` int(11) unsigned NOT NULL,
  `side_pos1` char(2) NOT NULL,
  `side1` varchar(255) NOT NULL,
  `pos1` char(2) NOT NULL,
  `hh1` char(2) NOT NULL,
  `mm1` char(2) NOT NULL,
  `ss1` char(2) NOT NULL,
  `atl1` varchar(255) NOT NULL,
  `side_pos2` char(2) NOT NULL,
  `side2` varchar(255) NOT NULL,
  `pos2` char(2) NOT NULL,
  `hh2` char(2) NOT NULL,
  `mm2` char(2) NOT NULL,
  `ss2` char(2) NOT NULL,
  `atl2` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1311 DEFAULT CHARSET=utf8;

# Dumping data for table editz.to_import: ~1.025 rows (approximately)
DELETE FROM `to_import`;
/*!40000 ALTER TABLE `to_import` DISABLE KEYS */;
INSERT INTO `to_import` (`id`, `reference`, `trackid`, `side_pos1`, `side1`, `pos1`, `hh1`, `mm1`, `ss1`, `atl1`, `side_pos2`, `side2`, `pos2`, `hh2`, `mm2`, `ss2`, `atl2`) VALUES
    (1, 205, 550, '0', 'Single Side', '0', '??', '??', '??', 'Noizefucker - Tons Of Bluesteel - Special Forces', '0', 'Single Side', '0', '??', '??', '??', 'Noizefucker - Tons Of Bluesteel - Special Forces'),
    ... some lines, approx 1300)...
    (1310, 268, 463, '#', '', '20', '00', '41', '00', 'Ingler - Trek', '#', '', '20', '00', '41', '00', 'Ingler - Trek');
/*!40000 ALTER TABLE `to_import` ENABLE KEYS */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用phpMyAdmin导入时,我收到此消息:

#1231 - Variable 'sql_mode' can't be set to the value of 'NULL' 
Run Code Online (Sandbox Code Playgroud)

为什么?我怎样才能解决这个问题呢?我正在使用HeidiSql 6导出该表...

实际上表和数据都添加在我的数据库中,只是我不明白为什么那个消息......

ste*_*yre 11

如果您发布的代码是您正在运行的整个代码,那么原因将是:

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
Run Code Online (Sandbox Code Playgroud)

通常,您还可以在SQL转储的顶部将其保留在转储之前保留原始值:

/*!40101 SET OLD_SQL_MODE=@SQL_MODE */;
Run Code Online (Sandbox Code Playgroud)

在你发布的内容中,这是省略的,所以@OLD_SQL_MODE是NULL,所以最后你要将它设置为NULL.


小智 5

我没有使用过 phpMyAdmin 但也许它与实际声明数据库的 sql 模式有关?

SQL 模式定义数据库应支持哪些语法以及应执行哪些验证检查。

在 Mysql 中,您可以通过命令行检查 sql 模式的声明方式:

mysql> SELECT @@sql_mode;
Run Code Online (Sandbox Code Playgroud)

SQL模式概述

模式列表