lower_case_table_names设置为2,Workbench仍然不允许使用小写数据库名称

dis*_*kid 8 mysql mysql-workbench

我在我的Windows 7 64位上安装MySql Workbench 6.2MySql version 5.6.

我想在我的数据库名称和表名中使用大写字母.所以我需要将变量设置lower_case_table_names为2.当我查看我的选项文件的常规选项卡时,它看起来如下所示: 在此输入图像描述 单击"应用"将打开一个"无变化"对话框.无论如何,当我尝试使用大写字母创建数据库时,我收到警告:

服务器配置了lower_case_table_names = 1,它只允许模式和表名中的小写字符.

我感觉my.ini服务器上的文件与选项文件配置中提到的文件不同.当我尝试在我的my.ini文件中手动添加此变量时,我看到下面的文本:

# *** 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.
Run Code Online (Sandbox Code Playgroud)

这就是我几天来一直困在创建模式的过程中.

O. *_*nes 6

在Windows中,表命名不区分大小写.也就是说,您的Customer表和customer表在Windows上将始终相同.这是NT文件系统的限制.当您的MySQL 服务器在Windows平台上运行时,这适用.您的Workbench客户端在哪里运行并不重要.

(您可以在Linux,BSD等上为不同的表使用混合大小写的表名,但这被认为是非常糟糕的做法:只有当您想让同事疯狂时才这样做.所以要小心.)

如果lower_case_table_names单独保留此设置,则可以在表名中使用大小写混合大小写而不会出现问题.

my.ini服务器启动时实际使用的文件通常位于data目录中.安装过程可以复制该文件的预装的版本,就像my_large.ini之上my.ini取决于你正在尝试做的.

  • "如果单独保留此lower_case_table_names设置,则可以在表名中使用大小写,而不会出现问题." 我无法添加名为`Campaign`的表.它将被改为`campaign`.但我可以在列名中使用混合大小写. (6认同)

小智 5

lower_case_table_names将 other更改为除 之外的任何设置后,您甚至无法启动 mysqld 1,这是默认设置。

0=>如果您在数据目录驻留在不区分大小写的文件系统(例如在 Windows 或 macOS 上)的系统上运行 MySQL lower_case_table_names0则不应设置为。这是一种不受支持的组合,可能会导致挂起情况。

但是让我们尝试将其更改为 2:

# Specifies the on how table names are stored in the metadata.
# If set to 0, will throw an error on case-insensitive operative systems
# If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive.
# If set to 2, table names are stored as given but compared in lowercase.
# This option also applies to database names and table aliases.
# NOTE: Modify this value after Server initialization won't take effect.
lower_case_table_names=2
Run Code Online (Sandbox Code Playgroud)

C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 8.0\my.ini"

ERROR [MY-011087] [Server, Different lower_case_table_names settings for server ('2') and data dictionary ('1').
ERROR [MY-010020] [Server, Data Dictionary initialization failed.
Run Code Online (Sandbox Code Playgroud)

初始化后,不允许更改此设置。所以lower_case_table_names需要和 一起设置--initialize

禁止lower_case_table_names使用与服务器初始化时使用的设置不同的设置启动服务器。该限制是必要的,因为各种数据字典表字段使用的排序规则基于服务器初始化时定义的设置,并且使用不同的设置重新启动服务器会在如何排序和比较标识符方面引入不一致。

mysqld --initialize --console --lower_case_table_names=2

然后在使用以下命令再次初始化服务器后,您将在工作台中收到以下错误lower_case_table_names=2

A server configuration problem was detected. The server is in a system that does not properly support the selected lower_case_table_names option value. Some problems may occur.
Run Code Online (Sandbox Code Playgroud)

显示变量,如lower_case_table_names

+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_table_names | 2     |
Run Code Online (Sandbox Code Playgroud)

所以结论:在 Windows 上将设置保留为 1,因为 0 或 2 不起作用,或者正如他们所说:可能会出现一些问题。

然而,我现在有我的数据库和表名以大写字母显示。这并没有多大作用,因为比较总是:

 # If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive.
 # If set to 2, table names are stored as given but compared in lowercase.
Run Code Online (Sandbox Code Playgroud)

尼古拉斯

  • 引用:“但是,我现在的数据库和表名称都以大写字母显示。” 您能解释一下您是如何做到这一点的吗?因为在上一句中,您似乎告诉人们不要使用 `lower_case_table_names=2`。那么我们应该还是不应该呢?这根本不符合逻辑。 (2认同)