mysql数据中文乱码_win10 系统解决mysql中文乱码问题
問(wèn)題:
向mysql 數(shù)據(jù)庫(kù)插入數(shù)據(jù)是,出現(xiàn)中文亂碼(中文均顯示為‘??’)
原因:
mysql 默認(rèn)的字符集是latin1,所以我么需要改為ut8編碼才可以
解決:
1、以管理員權(quán)限運(yùn)行cmd窗口
2、查看當(dāng)前字符集
>net start mysql
啟動(dòng)mysql服務(wù)
>mysql
進(jìn)入mysql運(yùn)行環(huán)境
>show variables like 'character%';
查看當(dāng)前字符集編碼情況
其中,character_set_client為客戶端編碼方式;
character_set_connection為建立連接使用的編碼;
character_set_database數(shù)據(jù)庫(kù)的編碼;
character_set_results結(jié)果集的編碼;
character_set_server數(shù)據(jù)庫(kù)服務(wù)器的編碼;
只要保證以上四個(gè)采用的編碼方式一樣,就不會(huì)出現(xiàn)亂碼問(wèn)題。
3、修改數(shù)據(jù)庫(kù)編碼格式
>select @@basedir;
在mysql環(huán)境中查看mysql的安裝位置
找到這個(gè)安裝位置,下圖為安裝位置下的文件
本機(jī)的mysql是通過(guò)解壓安裝的,開(kāi)始時(shí)只有my-default.ini文件,無(wú)my.ini文件
這時(shí)復(fù)制一份my-default.init并重命名為my.ini
打開(kāi)my.ini文件
在[mysqld] 下添加character-set-server=utf8
在[client] 下添加:default-character-set=utf8
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
character-set-server=utf8
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
port=3306
default-character-set=utf8
my.ini
保存文件
4、重新在mysql環(huán)境中查看字符編碼
發(fā)現(xiàn)這時(shí)的字符編碼已經(jīng)改為utf8
5、如果更改字符編碼之前已經(jīng)有創(chuàng)建的數(shù)據(jù)表,可以通過(guò)如下語(yǔ)句,更改已經(jīng)創(chuàng)建數(shù)據(jù)表的字符格式
mysql> alter table testapp_article convert to character set utf8;
也可以在創(chuàng)建數(shù)據(jù)表的時(shí)候指定使用utf8編碼,方法是在創(chuàng)建語(yǔ)句后加上character set = utf8
如:
create table test_table (
id int auto_increment,
title text,
content text,
posted_on datetime,
primary key (id)
) character set = utf8;
參考:
總結(jié)
以上是生活随笔為你收集整理的mysql数据中文乱码_win10 系统解决mysql中文乱码问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: html如何调整背景图片大小_如何快速调
- 下一篇: mysql where 拼接_分一个my