lowerCaseTableNames

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 数据库表,数据库名大小写铭感问题 mysql lower-case-table-names参数 线上有业务用到开源的产品,其中SQL语句是大小写混合的,而建表语句都是小写的,mysql默认设置导致这些执行失败。

数据库表,数据库名大小写铭感问题

mysql lower-case-table-names参数

线上有业务用到开源的产品,其中SQL语句是大小写混合的,而建表语句都是小写的,mysql默认设置导致这些执行失败。
就需要设置忽略大小写。设置lower-case-table-names=1,重启mysql实例生效。
这时就产生了另外一个问题,之前的大写字母的数据库名都失效了。都提示找不到数据库名。注释掉个lower-case-table-names=1.
则没有这个问题,因此这个问题肯定是lower-case-table-names参数引起的。故查找了官方解释:

Mysql官方文档的介绍:

Value

Meaning

0

Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE 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 Mac OS X). 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.

1

Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.

2

Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE 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 are stored in lowercase, as for lower_case_table_names=1.

 

默认为0,大小写敏感。

设置1,大小写不敏感。创建的表,数据库都是以小写形式存放在磁盘上,对于sql语句都是转换为小写对表和DB进行查找。

设置2,创建的表和DB依据语句上格式存放,凡是查找都是转换为小写进行。

 

If you plan to set the lower_case_table_names system variable to 1 on Unix, you must first convert your old database and table names to lowercase before stopping mysqld and restarting it with the new variable setting. To do this for an individual table, use RENAME TABLE:

 

当想设置lower_case_table_names = 1时,在重启数据库实例之前就需要将原来的数据库和表转换为小写。

 

官方文档的解释。要开启lower_case_table_names = 1 。先要将大写字母数据库更改为小写。否则将找不到数据库名。

 所以要想忽略大小写,还需要提前将大写数据库名更改小写,否则报错。数据库名无法rename.可以新建一个小写的数据库名。
然后rename table 到新的数据库,完成表的迁移。

在进行数据库参数设置之前,需要掌握这个参数带来的影响,切不可盲目设置。

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
6月前
|
Ubuntu Linux
将linux系统制作成iso镜像
将linux系统制作成iso镜像
|
Docker 容器
CPU内存不足分析Gitlab的内存消耗
CPU内存不足分析Gitlab的内存消耗
CPU内存不足分析Gitlab的内存消耗
|
Kubernetes 应用服务中间件 Docker
Docker——自定义网络实现
Docker——自定义网络实现
384 0
|
2月前
|
存储 关系型数据库 MySQL
lower_case_table_names 修改为何不生效
lower_case_table_names 是 MySQL 和 MariaDB 中的一个系统变量,它决定了数据库和表名在存储和引用时的大小写敏感性。这个变量有以下几个可能的值: 0:表名存储为给定的大小写,并区分大小写。这是大多数 Unix 系统的默认设置。 1:表名在存储和引用时都转换为小写,不区分大小写。这是 Windows 和 macOS 的默认设置。 2:表名存储为给定的大小写,但引用时不区分大小写。 如果你尝试修改 lower_case_table_names 的值但发现它不生效,可能是由以下几个原因造成的: 配置文件位置不正确:确保你在正确的配置文件中进行了修改。对于 MyS
109 2
|
10月前
|
SQL Nacos 数据库
Docker部署nacos单机版
Docker部署nacos单机版
314 0
|
11月前
|
NoSQL 数据可视化 Redis
Redis可视化管理工具:Another Redis DeskTop Manager
Redis可视化管理工具:Another Redis DeskTop Manager
1447 0
|
存储 移动开发 JavaScript
Vue3+TS+Vant3+Pinia(H5端)配置教程
Vue3+TS+Vant3+Pinia(H5端)配置教程
381 0
|
JavaScript Dubbo 小程序
Java中的 BigDecimal,80%的人都用错了....
Java中的 BigDecimal,80%的人都用错了....
|
JSON Kubernetes Java
kubenetes: patch更新和替换、删除资源内容
kubenetes: patch更新和替换、删除资源内容
1136 0
kubenetes: patch更新和替换、删除资源内容