Database error occurred 1267 illegal mix of collations (gbk_chinese_ci,implicit) and (utf8_general_ci,coercible) fo__ database

Source: Internet
Author: User
Tags mysql code mysql in php and mysql php website

when operating the MySQL database, the report "

error code [1267];

Illegal mix of collations (gbk_chinese_ci,implicit) and (utf8_general_ci,coercible) for operation ' like '

For the common garbled problem, some in the database itself has been GBK or gb2312 time, but the query is garbled, this is because MySQL in the connection process is also a way to encode, so the connection code set to gb2312 or Utf-8

Can be, such as:

Jdbc:mysql://localhost:3306/ipanel?useunicode=true&characterencoding=utf-8

Hibernate and JDBC parameter settings are not the same, but roughly the same, with a lot of similar information on the web.

The most important thing is the question:

Illegal mix of collations (gbk_chinese_ci,implicit) and (gb2312_chinese_ci,implicit) for operation ' = '

Believe that a lot of people encounter, meaning that the character encoding is not the same, can not be compared, that is, the internal code of the database is not the same, and some data is

GBK_CHINESE_CI, some data is gb2312_chinese_ci, so the core of solving this problem is to unify all the coding of the database.

Enter command line mode,

If the MySQL database is installed, you can use the following SQL commands to view MySQL's current character set settings:
Mysql> show VARIABLES like ' character_set_% ';
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | Latin1 |
| character_set_connection | Latin1 |
| Character_set_database | Latin1 |
| Character_set_results | Latin1 |
| Character_set_server | Latin1 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
7 Rows in Set (0.00 sec)

Mysql> show VARIABLES like ' collation_% ';
+----------------------+-------------------+
| variable_name | Value |
+----------------------+-------------------+
| collation_connection | Latin1_swedish_ci |
| Collation_database | Latin1_swedish_ci |
| Collation_server | Latin1_swedish_ci |
+----------------------+-------------------+
3 Rows in Set (0.00 sec)

Execute sequentially:

Set Character_set_client =gb2312;

Set Character_set_connection =gb2312;

Set Character_set_database =gb2312;

Set Character_set_results =gb2312;

Set Character_set_server =gb2312;

Set Character_set_system =gb2312; --Here utf-8 can also

Then execute:

SET Collation_server = Gb2312_chinese_ci


SET collation_database = Gb2312_chinese_ci

SET collation_connection =gb2312_chinese_ci

After the execution, please check the MySQL under each database, table, fields are gb2312, is not changed to come, this way will not appear

Illegal mix of collations (gbk_chinese_ci,implicit) and (gb2312_chinese_ci,implicit) for operation ' = ' This error, there is information on the net to reload, In fact, there is no need to change the code can be

*****************************

php5.2+mysql5.1+apache2.29 Ie6,firefor2,firefox3
The following problem occurs when a PHP Web page inserts a record into the MySQL database.
Illegal mix of collations (gbk_chinese_ci,implicit) and (latin1_swedish_ci,coercible) for operation ' = ' ... 。。
Solution: 1. Note the PHP website charset=utf-8 "
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
2. Database connection set to UTF8 encoding

<?php
# filename= "Connection_php_mysql.htm"
# type= "MYSQL"
# http= ' true '
$hostname _member = "localhost";
$database _member = "Member";
$username _member = "root";
$password _member = "123456";
$member = Mysql_pconnect ($hostname _member, $username _member, $password _member) or Trigger_error (Mysql_error (), E_user _ERROR);
mysql_query ("Set names GBK");
?>
Please modify to mysql_query ("Set names UTF8");
Please note that the PHP and MySQL code send the same question. Has nothing to do with MySQL database coding
Have a problem contact

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.