Mysql学习(一)命令行中文显示问题

1、修改my.ini文件中的字符全部为utf8

2、查看sql文件,确保里面是utf8编码

3、修改命令行文字设置

dos指令: 
chcp 65001 就是换成UTF-8代码页 
chcp 936 可以换回默认的GBK 
chcp 437 是美国英语 
如何在DOS窗口中显示UTF-8字符 
在中文Windows系统中,如果一个文本文件是UTF-8编码的,那么在CMD.exe命令行窗口(所谓的DOS窗口)中不能正确显示文件中的内容。在默认情况下,命令行窗口中使用的代码页是中文或者美国的,即编码是中文字符集或者西文字符集。 
如果想正确显示UTF-8字符,可以按照以下步骤操作: 
1、打开CMD.exe命令行窗口 
2、通过 chcp命令改变代码页,UTF-8的代码页为65001 
chcp 65001 
执行该操作后,代码页就被变成UTF-8了。但是,在窗口中仍旧不能正确显示UTF-8字符。 
3、修改窗口属性,改变字体 
在命令行标题栏上点击右键,选择"属性"->"字体",将字体修改为True Type字体"Lucida Console",然后点击确定将属性应用到当前窗口。 
这时使用type命令就可以显示UTF-8文本文件的内容了:

以上只能解决显示中文的问题,但是不能解决插入和查询中文的问题

以下是解决查询和插入中文的问题
my.ini文件里面设置如下

[client]

port=3306
default-character-set=gbk
[mysql]

default-character-set=gbk


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306


#Path to installation directory. All paths are usually resolved relative to this.
basedir="D:/mysql/5.5.20/"

#Path to the database root
datadir="E:/Data/Mysql/data"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8
character_set_client = utf8

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

命令行里面设置为

chcp 936 可以换回默认的GBK,将字体修改为True Type字体"Lucida Console",然后点击确定将属性应用到当前窗口。

然后打开mysql命令行设置set names gbk; 此时就可以正确显示中文了

发布了24 篇原创文章 · 获赞 13 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_39359584/article/details/88614433