Several implicit conversions of MySQL

Source: Internet
Author: User

1. The table definition is a character type, and an int is passed in

2. Character set inconsistency. The field defined by the table is GBK, which is passed into the UTF8; This occurs more in the stored procedure.

The character set of the database UTF8

Mysql> Show CREATE Database jstmonitor;
+------------+---------------------------------------------------------------------+
| Database | Create Database |
+------------+---------------------------------------------------------------------+
| Jstmonitor | CREATE DATABASE ' jstmonitor '/*!40100 DEFAULT CHARACTER SET UTF8 */| |
+------------+---------------------------------------------------------------------+
1 row in Set (0.00 sec)

The character set of the table GBK

Mysql> Show CREATE TABLE T1\g
1. Row ***************************
Table:t1
Create table:create Table ' T1 ' (
' col1 ' varchar () not NULL,
' Col2 ' bigint (one) not NULL DEFAULT ' 0 ',
PRIMARY KEY (' col1 ')
) Engine=innodb DEFAULT CHARSET=GBK
1 row in Set (0.00 sec)

A stored procedure was created:

Mysql> Show CREATE PROCEDURE Proc1\g
1. Row ***************************
Procedure:proc1
Sql_mode:
Create procedure:create definer= ' root ' @ ' 127.0.0.1 ' Procedure ' proc1 ' (in isn CHAR (20))
BEGIN
START TRANSACTION;
SELECT col2 from T1 WHERE col1= isn for UPDATE;
COMMIT;
END
Character_set_client:latin1
Collation_connection:latin1_swedish_ci
Database Collation:utf8_general_ci
1 row in Set (0.00 sec)

Calling the stored procedure: Call Proc1 (' tr ');

Show Processlist See the result:

| 878794 | Root | 127.0.0.1:43746 | Jstmonitor |      Query | 10 | Waiting for table level lock |         SELECT col2 from T1 WHERE col1= name_const (' isn ', _utf8 ' tr ' COLLATE ' utf8_general_ci ') for UPDATE |             0 |         0 | 1 |

The input column of the stored procedure requires an explicit definition of the input character set, otherwise the character set of its input column inherits from the library's character set.

If the library's character set and the field's character set are inconsistent, an implicit conversion occurs.

3. When multiple tables are associated, the character set of the associated fields is inconsistent;

Several implicit conversions of MySQL

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.