萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> mysql提示:Illegal mix of collations for operation ‘UNION’

mysql提示:Illegal mix of collations for operation ‘UNION’

 語句很簡單

 代碼如下  

<?php
$connection=mysql_connect("localhost","root","password"); //連接並選擇數據庫服務器
mysql_select_db("test",$connection);
$query="select * from users where name='你好'";
$result=mysql_query($query,$connection);
while($row=mysql_fetch_array($result))
{
echo "用戶ID:".$row[0]."<br>"; //也可以寫做$row["user_id"]
echo "用戶名:".$row[1]."<br>"; //也可以寫做$row["user_name"]
}
?>

  運行結果提示

  Error: Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation '='

  意思是說:操作符“=”比較的字符集不一致,一個是gbk_chinese_ci,一個是latin1_swedish_ci。

  首先、查看mysql的my.cnf,確認為utf8

 代碼如下  


mysql> show variables like "%char%";

+--------------------------+-------------------------------------+

| Variable_name            | Value                               |

+--------------------------+-------------------------------------+

| character_set_client     | utf8                                |

| character_set_connection | utf8                                |

| character_set_database   | latin1                              |

| character_set_filesystem | binary                              |

| character_set_results    | utf8                                |

| character_set_server     | utf8                                |

| character_set_system     | utf8                                |

| character_sets_dir       | D:/MySQL Server 5.0/share/charsets/ |

+--------------------------+-------------------------------------+

8 rows in set (0.00 sec)


 

 

copyright © 萬盛學電腦網 all rights reserved