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

lower_case_table_names set to 2, Workbench still does not allow lowercase database name

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

我想在我的数据库名称和 table 名称中使用大写字母。所以我需要将变量 lower_case_table_names 设置为 2。当我查看选项文件的常规选项卡时,它看起来如下所示: 单击“应用”会打开一个对话框,显示 "There Are No Changes"。 无论如何,当我尝试使用大写字母创建数据库时,我收到警告:

The server is configured with lower_case_table_names=1 which only allows lowercase characters in schema and table names.

我感觉服务器上的 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.

这就是我这几天一直在创建我的模式的原因。

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

(您可以在 Linux、BSD 等平台上为不同的 table 使用混合大小写的 table 名称,但它被认为是非常糟糕的做法:只有在以下情况下才这样做你想让你的同事发疯。所以要小心。)

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

服务器启动时实际使用的my.ini文件通常在data目录中。安装过程可以复制该文件的预加载版本,例如 my.ini 之上的 my_large.ini,具体取决于您要执行的操作。

如果您的数据文件位于不同于 C: 驱动器的驱动器上,您实际上可能有 2 个 "my.ini" 文件,一个将在 C: 驱动器上,当您编辑 [=15] 中的选项时=],这是在 "My.ini" 您的系统实际运行时发生更改的文件。 检查 C:\Program Data\MySQL\MySQL(server version),看看那里是否有 .ini 文件。如果是这样,您可能会发现文件底部有更改,需要将这些更改写入实际存储数据的驱动器上的实际工作 .ini。

在 workbench 中转到:管理面板 > 选项文件 > 常规 > 系统 >

检查"lower_case_table_names",输入值2。

关闭 Workbench。 重新启动服务 MYSQL56

在此处查看 img How to enable

  1. /etc/mysql/my.cnf
  2. 编辑此文件
  3. 添加以下行:

[mysqld]

lower_case_table_names=1

  1. 重启mysqlsudo /etc/init.d/mysql restart

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

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

但让我们尝试将其更改为 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

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.

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

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

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

使用 lower_case_table_names=2 再次初始化服务器后,您将在 workbench 中收到以下错误:

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.

显示变量 lower_case_table_names;

+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_table_names | 2     |

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

不过现在我的数据库和 table 名称都显示为大写字母。 这并没有多大作用,因为比较总是:

 # 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.

尼古拉斯