---
title: OceanBase 数据库 MySQL 模式查询如何区分大小写-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于OceanBase 数据库 MySQL 模式查询如何区分大小写相关的常见问题和使用技巧，帮助您快速解决OceanBase 数据库 MySQL 模式查询如何区分大小写的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# OceanBase 数据库 MySQL 模式查询如何区分大小写

更新时间：2026-05-26 09:46

适用版本： V2.1.x、V2.2.x、V3.1.x、V3.2.x、V4.0.x、V4.1.x、V4.2.x 内容类型：How-to  

## 适用版本

OceanBase 数据库所有版本。

## 问题现象

OceanBase 数据库 MySQL 模式，现在字段值里面保存的两个值只有大小写区分，发现 SQL 把两条都出来了吗，查询后不区分大小写。

```shell
mysql> select * from test where name = 'aaa';

```

```shell
+------+------+
| id   | name |
+------+------+
|    3 | aaa  |
|    3 | AAA  |
+------+------+
2 row in set (0.01 sec)

```

## 问题原因

表的 collate 校对规则和用于判断的字符的 collate 校对规则不一致。

## 解决方法

OceanBase 数据库 V2.x 和 V3.x 版本通过加 binary 来临时解决。

```shell
mysql> select * from test where binary name = 'aaa';
+------+------+
| id   | name |
+------+------+
|    3 | aaa  |
+------+------+
1 row in set (0.01 sec)

```

```shell
mysql> select * from test where binary name = 'AAA';
+------+------+
| id   | name |
+------+------+
|    3 | AAA  |
+------+------+
1 row in set (0.00 sec)

```

OceanBase 数据库 V4.x 及以后版本直接更改表的 collate 规则即可。

```shell
mysql> ALTER TABLE cesi27 MODIFY COLUMN name VARCHAR(25) CHARACTER  SET utf8 COLLATE utf8_bin;
Query OK, 0 rows affected (5.32 sec)

mysql> select * from cesi27 where name = 'xiaohei';
+----+---------+----------+
| id | name    | classnum |
+----+---------+----------+
|  1 | xiaohei | class1   |
+----+---------+----------+
1 row in set (0.02 sec)

mysql> select * from cesi27 where name = 'XIAOHEI';
+----+---------+----------+
| id | name    | classnum |
+----+---------+----------+
|  6 | XIAOHEI | class2   |
+----+---------+----------+
1 row in set (0.00 sec)

```

上一篇

[如何转换查询结果为 JSON 数组](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000450147)

下一篇

[含多个 in 和向量表达式的 SQL 执行报错 4016](https://www.oceanbase.com/knowledge-base/oceanbase-database-20000043623) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
