Mysql 8默认安装配置table名大小写不敏感

前一篇文章Ubuntu 18.04离线安装Mysql 8.0.26,详细介绍了如何安装mysql8,但是安装完毕后,用起来经常会遇到命名表存在却,提示找不到表的异常,经过调查,发现是在安装时,初始化没有做好,直接用大小写敏感的配置。
本文就来记录一下,安装mysql8配置table名大小写不敏感相关调整的过程。

一、原因分析

安装完成mysql8后,再在配置文件(/etc/mysql/mysql.conf.d/mysqld.cnf)末尾添加

lower_case_table_names=1

这种操作是无效的,因为官网有如下表述

lower_case_table_names can only be configured when initializing the server. Changing the lower_case_table_names setting after the server is initialized is prohibited.

只有在初始化的时候设置 lower_case_table_names=1才有效

那么,我们改怎么办呢,还记得之前有些过一个install的脚本吗

没错,初始化的操作就是最后一个执行语句里的

sudo dpkg -i mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb

在执行安装前,先把最后一行注释掉

 sudo dpkg -i mysql-common_8.0.26-1ubuntu18.04_amd64.deb
 sudo dpkg-preconfigure mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb

 sudo dpkg -i mysql-community-client-plugins_8.0.26-1ubuntu18.04_amd64.deb
 sudo dpkg -i libmysqlclient21_8.0.26-1ubuntu18.04_amd64.deb
 sudo dpkg -i libmysqlclient-dev_8.0.26-1ubuntu18.04_amd64.deb

  
 sudo dpkg -i mysql-community-client-core_8.0.26-1ubuntu18.04_amd64.deb
 sudo dpkg -i mysql-community-client_8.0.26-1ubuntu18.04_amd64.deb
 sudo dpkg -i mysql-client_8.0.26-1ubuntu18.04_amd64.deb

 sudo dpkg -i libmecab2_0.996-5_amd64.deb
 sudo dpkg -i mysql-community-server-core_8.0.26-1ubuntu18.04_amd64.deb
 # sudo dpkg -i mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb

后面调整后再手动执行。

二、修改初始化包

上面提到初始化时在包mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb内执行的,那么它的配置必然也在该包内,我只需要打开此包,修改后,在压包即可。

下面先介绍一下bed文件的解压包。

1. bed文件解包压包

解压出包内容
dpkg -X target.deb target/
解压出包的控制信息target/DEBIAN/下:
 dpkg -e target.deb target/DEBIAN/
对修改后的内容重新进行打包生成deb包
 dpkg-deb -b target/ target.deb

进过以上上即可完成修改

2. 修改

执行以下命令进行解压内容
dpkg -X mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb mysql8/
解压出包的控制信息:
 dpkg -e mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb mysql8/DEBIAN/
修改默认配置

默认配置文件目录如下:
···
/~/mysql8/etc/mysql/mysql.conf.d
···
打开,在末尾添加lower_case_table_names=1

# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
datadir     = /var/lib/mysql
log-error   = /var/log/mysql/error.log
lower_case_table_names=1

修改后保存关闭文件。

对修改后的内容重新进行打包生成deb包
 dpkg-deb -b mysql8/ mysql8.deb

三、执行始化

调整完毕后,执行新压缩的包

sudo dpkg -i mysql8.deb

OK,即可搞定

你可能感兴趣的:(Mysql 8默认安装配置table名大小写不敏感)