您好,登錄后才能下訂單哦!
現象:
mysql 5.6
主從報下面的錯誤:
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: ****
Master_User: ucloudbackup
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 43347
Relay_Log_File: mysql-relay.000002
Relay_Log_Pos: 1810
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1270
Last_Error: Error 'Illegal mix of collations (utf8_general_ci,COERCIBLE), (latin1_swedish_ci,IMPLICIT), (utf8_general_ci,COERCIBLE) for operation 'concat'' on query. Default database: 'test'. Query: 'INSERT INTO test (addressType, addressName) VALUES ('sh_jincheng', concat('上海市', NAME_CONST('i',180),'室'))'
Skip_Counter: 0
Exec_Master_Log_Pos: 1647
Relay_Log_Space: 43710
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1270
Last_SQL_Error: Error 'Illegal mix of collations (utf8_general_ci,COERCIBLE), (latin1_swedish_ci,IMPLICIT), (utf8_general_ci,COERCIBLE) for operation 'concat'' on query. Default database: 'test'. Query: 'INSERT INTO test (addressType, addressName) VALUES ('sh_jincheng', concat('上海市', NAME_CONST('i',180),'室'))'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 169052043
Master_UUID: a2b11ba1-1552-11e7-a33b-52540059bf44
Master_Info_File: /opt/udb/instance/mysql-5.6/2f2a1aea-b636-48b7-9006-a1af025d90d0/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 170330 22:19:10
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: a2b11ba1-1552-11e7-a33b-52540059bf44:1-105
Executed_Gtid_Set: a2b11ba1-1552-11e7-a33b-52540059bf44:1-5
Auto_Position: 0
1 row in set (0.00 sec)
原來有一個筆記 ,里面寫到:
ERROR 1267 concat name_const函數
今天朋友他們有一個錯誤,最后是因為:
MySQL> select concat('¥',NAME_CONST('tttt',1234));
ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation 'concat'
這個類似的錯誤原來也見過:那是因為兩表關聯時,關聯的字段是有索引的,但是索引不是按的相同的COLLATION,所以出現的問題,修改為一樣之后,即可正常。
又試了一下
MySQL> select concat('a',NAME_CONST('tttt',1234));
+-------------------------------------+
| concat('a',NAME_CONST('tttt',1234)) |
+-------------------------------------+
| a1234 |
+-------------------------------------+
1 row in set (0.00 sec)
MySQL> select concat('工',NAME_CONST('tttt',1234));
ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation 'concat'
從這里看,用漢字的類的就不正常。
MySQL> select COLLATION('工');
+------------------+
| COLLATION('工') |
+------------------+
| utf8_general_ci |
+------------------+
1 row in set (0.00 sec)
MySQL> select COLLATION('a');
+-----------------+
| COLLATION('a') |
+-----------------+
| utf8_general_ci |
+-----------------+
1 row in set (0.00 sec)
MySQL> select COLLATION('¥');
+------------------+
| COLLATION('¥') |
+------------------+
| utf8_general_ci |
+------------------+
1 row in set (0.00 sec)
MySQL> select COLLATION(NAME_CONST('tttt',1234));
+------------------------------------+
| COLLATION(NAME_CONST('tttt',1234)) |
+------------------------------------+
| binary |
+------------------------------------+
1 row in set (0.00 sec)
有點暈了,前前看 'a','工','¥' 都是一樣的, 漢字的不行。
看看這個函數:
This function is for internal use only,可以寫成別的方式
比如這里的
MySQL> select NAME_CONST('tttt',1234);
+------+
| tttt |
+------+
| 1234 |
+------+
1 row in set (0.00 sec)
可以寫為:
MySQL> select 1234 as 'tttt';
+------+
| tttt |
+------+
| 1234 |
+------+
1 row in set (0.00 sec)
一樣的效果 。
另:
MySQL> select concat('¥',NAME_CONST('tttt','1234'));
+-----------------------------------------+
| concat('¥',NAME_CONST('tttt','1234')) |
+-----------------------------------------+
| ¥1234 |
+-----------------------------------------+
這樣也不會報錯:
不知道開發到底是什么 意思 ,和開發商量 才好最后約定怎么搞。
當時朋友遇到這個問題,最后他們也沒有反饋這個是怎么回事,我也就忘記了這個事情,這次是自己遇到這個問題,并且分析問題時較之前也多了一些方法,這次就從源代碼看下這個問題。
看了幾分鐘代碼,有一個懷疑點是 存儲過程的調用引起的這個問題(是在subst_spvars函數中完成的,這里就不列出來代碼了),就去主庫查看,果然有這個procedure,
重現方法:
在主庫上建表:
主庫Binlog_format=mixed;
CREATE TABLE `test` (
`addressId` int(11) NOT NULL AUTO_INCREMENT,
`addressType` varchar(30) NOT NULL,
`addressName` varchar(300) NOT NULL,
`usable` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`addressId`)
) ENGINE=InnoDB AUTO_INCREMENT=202 DEFAULT CHARSET=utf8mb4
在主庫上建procedure:
delimiter //
CREATE PROCEDURE `test_insert`()
BEGIN
DECLARE i INT DEFAULT 180;# can not be 0
WHILE i<400
DO
INSERT INTO test (addressType, addressName) VALUES ('sh_jincheng', concat('上海市',i,'室'));
SET i=i+1;
END WHILE ;
commit;
END
//
delimiter ;
調用procedure:
mysql> call test_insert();
Query OK, 0 rows affected (0.21 sec)
從庫上就會報上面的錯.
解決方法:
可以把 binlog_format=row 解決這個問題
聲明:源碼新手,僅代表個人意見,非權威,如果誤導看官,見諒。
QQ 273002188 歡迎一起學習
QQ 群 236941212
oracle,mysql,PG 相互交流
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。