解决linux上安装mysql5.7以上版本没有my.cnf配置文件的问题
Question:在公司服务器上部署项目时,将sql脚本导入到服务器后启动程序,发现好多SQL语句在编写时,表名都有大小写的区分,而Linux安装的mysql数据库,默认是严格区分大小写的,于是输入命令"mysql -uroot -p"进入mysql后端,输入"show VARIABLES like ‘lower%’; "查看区分大小写是如何配置的:
lower_case_table_names 0表示区分大小写 1表示不区分大小写
需要修改配置文件my.cnf 在[mysqld] 最后添加一行
lower_case_table_names = 1
但是发现安装了mysql5.7.26后没有my.cnf文件。
便开始查阅大量资料
从Oracle官方了解到:mysql5.7.18 开始不在二进制包中提供 my-default.cnf 文件。
经过测试,在 5.7.18 版本中,使用 tar.gz 安装时,也就是压缩包解压出来安装这种,已经不再需要 my.cnf 文件也能正常运行。
my.cnf 文件就是把在命令行上启动 MySQL 时后面的参数用 cnf 文件配置好,那么下载启动时就不再需要在命令上加如参数。
这个 my.cnf 文件可以是自定义位置,也可以使用如下默认的位置,只要放在默认位置,MySQL自动识别(通过 deb 或者 APT 源安装的,初始位置在下方列表):
文件名 | 目的 |
---|---|
/etc/my.cnf | 全局选项 |
/etc/mysql/my.cnf | 全局选项 |
SYSCONFDIR/my.cnf | 全局选项 |
$MYSQL_HOME/my.cnf | 服务器特定选项(仅限服务器) |
defaults-extra-file | 指定的文件 --defaults-extra-file,如果有的话 |
~/.my.cnf | 用户特定选项 |
~/.mylogin.cnf | 用户特定的登录路径选项(仅限客户端) |
总之,无论是使用 APT 源安装还是 deb 包安装,或者二进制(压缩包 tar.gz )包安装的,都可以通过 my.cnf 文件进行配置来达到 MySQL 的启动配置及调优。
重点:对于Linux上安装完mysql.5.7xxx版本后,可以按照以下步骤设置mysql的配置文件my.cnf:
1. 先停止mysql服务,输入快捷命令pkill mysql
2. 在/etc目录下创建文件my.cnf,输入快捷命令touch my.cnf
3. 在创建的这个文件中进行参数设置,可以参考如下设置:
由于在 5.7.18 开始,二进制包不再包含示例文件 my-default.cnf,所以我从 5.7.17 版本中提取了样例,但是发现里面也没有太多项配置,my-default.cnf 内容如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** 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.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = ....