我有一個網站,當你複製從Microsoft Word等具體應用,爲在我的網站上搜索框中輸入一些字符(*,' " - _
)我意識到,它返回此錯誤:設置CentOS 6的mysql的字符集爲UTF8
ERROR org.hibernate.util.JDBCExceptionReporter - Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
所以我去看看我的數據庫,我想看看,如果數據庫中使用UTF-8。
mysql> SHOW VARIABLES LIKE '%character%';
+--------------------------+----------------------------+
| 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 | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE '%collation%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
正如你所看到的,數據庫使用latin1
,我想將它設置爲使用utf8
。所以,首先我是一個Centos 6.2
服務器和文件my.cnf
文件駐留在/etc/my.cnf
和文件是[mysqld]
下如下:
[mysqld]
local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
init_connect ='SET NAMES utf8'
character_set_server = utf8
collation_server = utf8_general_ci
PS我並不擔心[client]
節,因爲它表明,它使用utf8
的值爲character_set_client
。
問題:
雖然我試圖將服務器設置在我my.cnf
文件(並關閉該文件,關閉我的Tomcat和重新啓動我的Tomcat的)。沒有什麼改變。當我運行我顯示的第一個查詢時,它仍然顯示character_set_server
仍在使用latin1