【总结】MySQL非root安装-初始化数据库时unknown variable ‘defaults-file=**/my.cnf‘

问题描述

使用非root安装mysql,使用 mysqld 初始化数据库时,不想使用/etc/my.cnf作为启动配置文件,而是指定自定义的my.cnf文件,在执行时,遇到[ERROR] unknown variable 'defaults-file=/data/infra/mysql/conf/my.cnf' 错误。

执行的命令: ./bin/mysqld --initialize-insecure --user=ftops --defaults-file=/data/infra/mysql/conf/my.cnf --basedir=/data/infra/mysql --datadir=/data/infra/mysql/data --socket=/data/infra/mysql/tmp/mysql.sock

复制代码
[ftops@ft-d-0192168016209 mysql]$ ./bin/mysqld --initialize-insecure --user=ftops --defaults-file=/data/infra/mysql/conf/my.cnf --basedir=/data/infra/mysql --datadir=/data/infra/mysql/data --socket=/data/infra/mysql/tmp/mysql.sock
2024-03-20T01:55:15.764417Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-03-20T01:55:15.891443Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-03-20T01:55:15.918429Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-03-20T01:55:15.973263Z 0 [ERROR] unknown variable 'defaults-file=/data/infra/mysql/conf/my.cnf'
2024-03-20T01:55:15.973273Z 0 [ERROR] Aborting
[ftops@ft-d-0192168016209 mysql]$ rm -rf data/
[ftops@ft-d-0192168016209 mysql]$

原因

这个是mysql 的一个bug,使用指定路径的my.cnf,而不用默认的/etc/my.cnf文件,需要在启动时,将--default-file=***/my.cnf 参数放在命令后的第一位参数传入,如果是作为命令第二、第三位,就会出现上述错误。

错误的示范:./mysqld --initialize-insecure --defaults-file=/data/infra/mysql/conf/my.cnf

正确的示范:./mysqld --defaults-file=/data/infra/mysql/conf/my.cnf --initialize-insecure

参考:https://www.cnblogs.com/qiumingcheng/p/11191759.html

问题解决

将--defaults-file参数调整到命令第一位,即可解决。

示例:./bin/mysqld --defaults-file=/data/infra/mysql/conf/my.cnf --initialize-insecure --user=ftops --basedir=/data/infra/mysql --datadir=/data/infra/mysql/data --socket=/data/infra/mysql/tmp/mysql.sock

复制代码
[ftops@ft-d-0192168016209 mysql]$ ./bin/mysqld --defaults-file=/data/infra/mysql/conf/my.cnf --initialize-insecure --user=ftops  --basedir=/data/infra/mysql --datadir=/data/infra/mysql/data --socket=/data/infra/mysql/tmp/mysql.sock
2024-03-20T01:56:38.815353Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-03-20T01:56:38.842167Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-03-20T01:56:38.899853Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 171a1d3a-e65d-11ee-be91-faa23b88c700.
2024-03-20T01:56:38.900679Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-03-20T01:56:40.116747Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-03-20T01:56:40.116759Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-03-20T01:56:40.119760Z 0 [Warning] CA certificate ca.pem is self signed.
2024-03-20T01:56:40.300626Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
相关推荐
AI.NET 极客圈7 分钟前
.NET 原生驾驭 AI 新基建实战系列(四):Qdrant ── 实时高效的向量搜索利器
数据库·人工智能·.net
weixin_4708802639 分钟前
MySQL体系架构解析(二):MySQL目录与启动配置全解析
数据库·mysql·面试·mysql体系架构·mysql bin目录
英英_1 小时前
MySQL 日志数据同步的详细教程
数据库·mysql
Paddy哥1 小时前
linux 安装mysql8.0;支持国产麒麟,统信uos系统
linux·mysql·麒麟·统信uos·统信
TDengine (老段)2 小时前
TDengine 替换 Hadoop,彻底解决数据丢失问题 !
大数据·数据库·hadoop·物联网·时序数据库·tdengine·涛思数据
南棱笑笑生2 小时前
20250605使用boot-repair来恢复WIN10和ubuntu22.04.6双系统的启动
数据库·postgresql
初次见面我叫泰隆2 小时前
Redis——1、服务端高并发分布式结构演进之路
数据库·redis·分布式
朝九晚五ฺ3 小时前
【MySQL基础】数据库的备份与还原
数据库·mysql·oracle
时序数据说3 小时前
时序数据库IoTDB的UDF Sample算法在数据监控、故障预防的应用
大数据·数据库·开源·时序数据库·iotdb
emo了小猫6 小时前
Mybatis #{} 和 ${}区别,使用场景,LIKE模糊查询避免SQL注入
数据库·sql·mysql·mybatis