原文地址: http://blog.duhbb.com/2022/02/09/on-mysql-low-case-table-names/
歡迎訪問我的博客: http://blog.duhbb.com/
引言
今天導庫, 啟動項目, 結果尼瑪項目起不來, changelog瘋狂執行, 正常情況下不會出現這樣的. 找了好半天原因才發現庫中存在同名但是大小寫不一致的表名.
背景知識
bug: https://bugs.mysql.com/bug.php?id=90695
MySQL 8.0 新增了data dictionary的概念,數據初始化的時候在linux下默認使用lower-case-table-names=0
的參數,數據庫啟動的時候讀取的my.cnf文件中的值。若二者值不一致則在mysql的錯誤日志中記錄報錯信息。
在MySQL 5.7 之前則允許數據庫初始化和啟動的值不一致且以啟動值為准。在MySQL 官方提供的RPM包中默認是使用lower-case-table-names=0
,不太適合生產環境部署。在生產環境建議使用官方的二進制包。
官方解釋:
After initialization, is is not allowed to change this setting.So "lower_case_table_names" needs to be set together with --initialize .
It is 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 determined by 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.
It is therefore necessary to configure lower_case_table_names to the desired setting before initializing the server. In most cases, this requires configuring lower_case_table_names in a MySQL option file before starting the MySQL server for the first time. For APT installations on Debian and Ubuntu, however, the server is initialized for you, and there is no opportunity to configure the setting in an option file beforehand. You must therefore use the debconf-set-selection utility prior to installing MySQL using APT to enable lower_case_table_names.
解決辦法:
在mysql數據庫初始化的時候指定不區分大小寫,在數據庫實例啟動的時候也要指定不區分大小寫。即數據庫初始化時lower_case_table_names
的值和數據庫啟動時的值需要一樣。
在實際開發生產的應用中多是不區分大小寫的即lower-case-table-names=1
。
MySQL 8.0表名大小寫問題
MySQL默認的lower-case-table-names
的值為0, 也就是大小寫敏感, 這個需要在初始化的時候指定, 不指定就是0, 1表示忽略表名大小寫.
mysqld --user=mysql --lower-case-table-names=1 --initialize-insecure --basedir=/usr/local/mysql --datadir=/data/mysql/node1
反正我在debian上用apt-get安裝時mysql data目錄默認是/var/lib/mysql
.
debian上的配置
刪除data目錄
先刪除mysql的data目錄, 由於我是本機環境, 所以不用備份.
重新初始化
mysqld --user=mysql --lower_case_table_names=1 --initialize-insecure
配置文件
my.cnf中加入如下的配置
[mysqld]
lower_case_table_names=1
到這里通過service mysql restart
基本就可以正常啟動了.
lower-case-table-names和lower_case_table_names區別
- mysql 配置 my.cnf 與 變量
show variables like ''
; 可能不一樣。 - 在 my.cnf中 有中杠, 有下划線; 不過中杠與下划線都支持。
注意:如果在配置文件里給出的某個選項是mysqld無法識別的,MySQL服務器將不啟動。
原文鏈接:https://blog.csdn.net/u011665746/article/details/79067637
MySQL查看默認變量的值
There are several ways to see the names and values of system variables:
To see the values that a server uses based on its compiled-in defaults and any option files that it reads, use this command:
mysqld --verbose --help
To see the values that a server uses based only on its compiled-in defaults, ignoring the settings in any option files, use this command:
mysqld --no-defaults --verbose --help
原文地址: http://blog.duhbb.com/2022/02/09/on-mysql-low-case-table-names/
歡迎訪問我的博客: http://blog.duhbb.com/