如何解决设置 lower_case_table_names=0 时无法连接到 'localhost' (10061) 上的 MySQL 服务器?

How to solve Can't connect to MySQL server on 'localhost' (10061) when setting lower_case_table_names=0?

在 mysql 中创建 table 时,我注意到我所有的 table 名称都以小写字母开头,即使我用大写字母命名它们也是如此。

我发现进入:

C:\ProgramData\MySQL\MySQL Server 8.0

打开 my.ini 文件并更改 lower_case_table_names=0

会根据this video的技巧。

完成上述操作后我关闭了服务器,重新启动了电脑 并且在尝试再次启动服务器时出现以下错误:

Could not connect, server may not be running. Can't connect to MySQL server on 'localhost' (10061)

当我变回来的时候lower_case_table_names=1

又能用了。我该如何解决?

编辑:

我发现我可以通过

更改 属性 而不是进入 ini 文件

Options file

然后在常规选项卡下我找到 lower_case_table_names 并将其更改为 0

但又是同样的错误。

我建议您为此配置使用值 2,因为您正尝试在 windows 机器上使用 0,这可能会导致数据库表出现问题,基于关于 documentation for windows/Mac OS usage for value 0:

Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or macOS). If you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.

在链接的文档中,值 2 可以解决您的问题,它将以您使用的相同名称将表存储在磁盘上,在这种情况下查找将不区分大小写:

Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case-sensitive! InnoDB table names and view names are stored in lowercase, as for lower_case_table_names=1.

如您所见https://bugs.mysql.com/bug.php?id=89035

自 8.0.5

It is now prohibited to start the server with a lower_case_table_names setting that is different from the setting used when the server was initialized. The restriction is necessary because collations used by various data dictionary table fields are based on the setting defined when the server is initialized, and restarting the server with a different setting would introduce inconsistencies with respect to how identifiers are ordered and compared.

禁止这样做,导致服务无法启动。