如何解决:mysql中文查询不出结果(软件与SQL语句都正常)

来源:互联网 发布:03湖人马刺数据统计 编辑:程序博客网 时间:2024/04/28 08:35

问题描述:(mysql)用英文作为查询关键字,所有都正常,用中文作为关键字查询不到,同时也不报错,另外通过日志打印,中文也无乱码,数据库也没有出现乱码,数据库的字符集与软件的字符集一样(这里假设都是utf-8)


问题分析:

首先描述中排除了软件问题,数据库与软件的字符集不一致问题。

那么,基本可以分析问题的方向:还是字符集的问题,一定是哪里还有默认的字符集没有设置(我们不知道而已)。


问题解决:

mysql有一个默认的启动配置,有个字符集需要设置,试试解决方案吧。

方法:修改mysql的安装目录的my.ini文件的字符集,并重启mysql(详细步骤如下)

例如我的安装目录是C:\Program Files (x86)\MySQL\MySQL Server 5.5(如果不知道,可以这么找:快捷键win+r(或开始-运行)->输入 services.msc ->找到mysql服务->右键查看属性->找到安装目录)

打开my.ini文件,修改以下内容(背景色的,将其修改为你要的字符集,我这里使用的是utf8),保存文件。

.....................
[client]port=3306[mysql]default-character-set=utf8# 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 onport=3306#Path to installation directory. All paths are usually resolved relative to this.basedir="C:/Program Files (x86)/MySQL/MySQL Server 5.5/"#Path to the database rootdatadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data/"# The default character set that will be used when a new schema or table is# created and no character set is definedcharacter-set-server=utf8# The default storage engine that will be used when create new tables whendefault-storage-engine=INNODB# Set the SQL mode to strictsql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
...........................


重启mysql(快捷键win+r(或开始-运行)->输入 services.msc ->找到mysql服务->右键菜单->重新启动)



你再试试吧。



阅读全文
0 0