Recently, when using a stored procedure that uses a MySQL database, some problems have been identified, the database encoding is inconsistent with the table and field encoding
Cause a problem when running, error message: 1267-illegal mix of collations
Through some methods on the net to solve the database system itself code, and the side of the code, but still did not solve the problem,
Then build the statement to look at the table:
CREATE TABLE' Dev_info ' (' ID ')int( One) not NULLauto_increment, ' dev_id 'int(Ten) not NULL, ' Dev_sta 'int(5) not NULL, ' Sta_name 'varchar(5)CHARACTER SETA COLLATE A_ci not NULL, ' SessionID 'varchar( -)CHARACTER SETA COLLATE A_ciNULL DEFAULT NULL ,PRIMARY KEY(' id ')) ENGINE=InnoDBDEFAULT CHARACTER SET=gb2312 COLLATE=gb2312_chinese_ciauto_increment= -Row_format=COMPACT;
Code a A_CI I just give an example of that, andgb2312 not the same code,
Found the problem, although the database and table encoding is the same, but the field encoding is not the same, so need to re-establish the table,
Build Table:CREATE TABLE' Dev_info ' (' ID ')int( One) not NULLauto_increment, ' dev_id 'int(Ten) not NULL, ' Dev_sta 'int(5) not NULL, ' Sta_name 'varchar(5)CHARACTER SETgb2312 COLLATE Gb2312_chinese_ci not NULL, ' SessionID 'varchar( -)CHARACTER SETgb2312 COLLATE Gb2312_chinese_ciNULL DEFAULT NULL ,PRIMARY KEY(' id ')) ENGINE=InnoDBDEFAULT CHARACTER SET=gb2312 COLLATE=gb2312_chinese_ciauto_increment= -Row_format=COMPACT;
This solves the problem, does not need to reload what database,
I found that the problem was written in a stored procedure that appeared inside, and by the way the stored procedure was put out, is to achieve the comparison of two strings
CREATEDefiner=' Root ' @ ' localhost 'PROCEDURE' Newproc ' (inch' app_dev_id 'int, Out ' app_session_id 'varchar( -))BEGIN#Routine body goes here ...DECLARE var INT;SET var =(SELECT COUNT(*) fromMysql_proce.dev_infoWHEREdev_id=app_dev_id);IF var=1 Then SELECTSessionID intoapp_session_id fromMysql_proce.dev_infoWHEREdev_id=app_dev_id;END IF;END;
MySQL database encoding re-set