在使用mysql5.7時(shí),會(huì)發(fā)現(xiàn)通過(guò)web端向數(shù)據(jù)庫(kù)中寫(xiě)入中文后會(huì)出現(xiàn)亂碼,但是在數(shù)據(jù)庫(kù)中直接操作SQL語(yǔ)句插入數(shù)據(jù)后中文就顯示正常,這個(gè)問(wèn)題怎么解決呢?此處不對(duì)MySQL的數(shù)據(jù)編碼過(guò)程和原理進(jìn)行講解,如果有興趣的同學(xué)可以自己百度。
下面我們就直接使用如下操作解決:
一、打開(kāi)mysql控制臺(tái),輸入命令show variables like 'character%';
顯示如下:
+--------------------------+-------------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\MySQL\MySQL Server 5.0\share\charsets\ |
+--------------------------+-------------------------------------------+
二、修改my.ini文件
[client]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
三、重啟后使用第一步的命令查看,如下:
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
還有character_set_database和character_set_server的默認(rèn)字符集還是latin1。
四、輸入命令:set names utf8;
重啟后,使用第一步命令查看:
+--------------------------+------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\wamp64\bin\mysql\mysql5.7.9\share\charsets\ |
+--------------------------+------------------------------------------------+
除了character_set_filesystem是binary外,其他都是utf8了,
這樣在web端也設(shè)置成utf8編碼就可以正常輸入數(shù)據(jù)庫(kù)了。
以上所述是小編給大家介紹的解決Mysql5.7中文亂碼的問(wèn)題,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
您可能感興趣的文章:- mysql中插入表數(shù)據(jù)中文亂碼問(wèn)題的解決方法
- 解決Linux下Tomcat向MySQL插入數(shù)據(jù)中文亂碼問(wèn)題
- JDBC連接mysql處理中文時(shí)亂碼解決辦法詳解
- 詳解mysql數(shù)據(jù)庫(kù)中文亂碼問(wèn)題
- 在CMD中操作mysql數(shù)據(jù)庫(kù)出現(xiàn)中文亂碼解決方案
- 關(guān)于servlet向mysql添加數(shù)據(jù)時(shí)中文亂碼問(wèn)題的解決
- Ubuntu下MySQL中文亂碼的問(wèn)題解決
- JSP MySQL插入數(shù)據(jù)時(shí)出現(xiàn)中文亂碼問(wèn)題的解決方法
- Mac Mysql數(shù)據(jù)庫(kù)中文亂碼問(wèn)題解決
- 解壓版MYSQL中文亂碼問(wèn)題解決方案