MySQL database encoding re-set

Source: Internet
Author: User
Tags compact

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.