如何将MySQL配置为区分大小写 [英] How to Configure MySQL to be Case Sensitive

查看:160
本文介绍了如何将MySQL配置为区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,对于MySQL服务器上的整个数据库,启用和禁用区分大小写的命令有哪些?我知道 COLLATE 语句,但是它似乎有必要将其放在每个运行的SQL语句中.是否可以选择全局设置?

What are the commands to enable and disable case sensitivity by default for an entire database on a MySQL server? I'm aware of the COLLATE statement, but it seems it's necessary to place this in every SQL statement that's run. Is there an option to set this globally?

推荐答案

要设置整个数据库的排序规则,可以使用:

To set the collation for the entire database, you can use:

CREATE DATABASE test_database CHARACTER SET utf8 COLLATE utf8_general_cs;

您还可以通过ALTER DATABASE更改现有数据库上的排序规则. (有关更多信息,请参见MySQL 数据库字符集和排序规则手动输入.)

You can also change the collation on an existing database via ALTER DATABASE. (For more information see the MySQL Database Character Set and Collation manual entry.)

但是,如果只需要将一个表区分大小写,则可以简单地使用:

If however, only a single table needs to be treated as case sensitive, you could simply use:

DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table (
  test_id bigint unsigned NOT NULL auto_increment,
  ...

  PRIMARY KEY test_id (test_id),
  ...
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_cs;

(不区分大小写的字符为"utf8_general_ci".)

(Case insensitive being "utf8_general_ci".)

最后,主要的MySQL 字符集支持手册部分值得一读. (它列出了MySQL支持的字符集和排序规则 ,告诉您如何在服务器上设置字符集/排序规则级别等)

Finally, the main MySQL Character Set Support manual section is probably worth a quick peruse. (It lists the character sets and collations supported by MySQL, tells you how to set the character set/collation at the server level, etc.)

这篇关于如何将MySQL配置为区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆