我正在尝试运行一个简单的主从 MySQL 复制,但是在使用 LOAD DATA INFILE 时出现一些奇怪的错误:
110908 23:59:42 [ERROR] Slave SQL: Error 'Unknown column 'N°_Site' in 'field list'' on query. Default database: 'b4_sites'. Query: 'LOAD DATA INFILE '/tmp/SQL_LOAD-116-4-6441.data' IGNORE INTO TABLE `cellule_1` FIELDS TERMINATED BY ';' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' IGNORE 1 LINES (`Region`, `V2G3G`, `Lac`, `CI`, `bsc_rnc`, `N°_Site`, `Constructeur`)', Error_code: 1054
110908 23:59:42 [Warning] Slave: Unknown column 'N°_Site' in 'field list' Error_code: 1054
110908 23:59:42 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000002' position 68303896
我们有Ubuntu 服务器 10.04 LTS在主服务器和从服务器上运行。MySQL 版本相同mysql-服务器-核心-5.1 - 5.1.41-3ubuntu12.10. 几乎相同的 MySQL 配置(如果需要我可以发布),没有什么特别的。
我可以看到表的一个字段名称中有一个特殊字符,这显然会引起错误,但奇怪的是查询在主服务器上执行时没有出现错误......
两台服务器上的字符集-主服务器:
mysql> show variables like "char%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
奴隶:
mysql> show variables like "char%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
欢迎任何帮助,提前致谢
答案1
我们找到了一个解决方案:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set=UTF8
...
,在大师级上。仅客户端部分...
或者:
mysql> SET NAMES UTF8;
因此,只有字段的名称是 UTF-8 的。