Heim  >  Artikel  >  Datenbank  >  mysql 用load data 导入数据时,数据被截断问题

mysql 用load data 导入数据时,数据被截断问题

WBOY
WBOYOriginal
2016-06-07 15:34:572509Durchsuche

在 MySQL 中使用 load data infile 命令导入数据文件到 MySQL 数据库中的时候,如果遇到 MySQL 错误:“ERROR 1261 (01000)” ,则很可能是由于数据文件中的列数跟 MySQL 数据表字段数目没有完全匹配,并且 sql_mode 设为 strict 模式的缘故。要想在这种情况

在 MySQL 中使用 load data infile 命令导入数据文件到 MySQL 数据库中的时候,如果遇到 MySQL 错误:“ERROR 1261 (01000)” ,则很可能是由于数据文件中的列数跟 MySQL 数据表字段数目没有完全匹配,并且 sql_mode 设为 strict 模式的缘故。要想在这种情况下继续导入数据到 MySQL 表中,则需要设置 MySQL sql_mode 变量。把“strict_trans_tables” 从 sql_mode 中去掉,如下:

查看 MySQL 当前连接的 sql_mode

mysql> show variables like 'sql_mode';

+---------------+----------------------------------------------------------------+
| Variable_name | Value                                                          |
+---------------+----------------------------------------------------------------+
| sql_mode      | strict_trans_tables,no_auto_create_user,no_engine_substitution |
+---------------+----------------------------------------------------------------+

设置 MySQL sql_mode,使其不包含 “strict_trans_tables” mode

set sql_mode='';

这样,就可以利用 MySQL load data infile,继续向 MySQL 中导入数据了。否则,MySQL 会终止导入过程,并抛出下面几种错误信息:

<strong>ERROR 1261 (01000): Row 1 does not contain data for all columns
ERROR 1262 (01000): Row 1 was truncated; it contained more data than there were input columns</strong>

 

本文由 www.sqlstudy.com


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn