You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新Windows PC上Laragon环境MySQL 8数据目录初始化失败求助

MySQL 8 在 Laragon 下初始化数据目录失败:auto.cnf 同步错误(OS errno 22 - Invalid argument)

问题描述

更换新Windows电脑后,Laragon环境中的MySQL 8无法正确初始化数据目录,执行初始化命令时出现auto.cnf同步相关错误,核心报错:

mysqld: Can't sync file 'M:\laragon\data\mysql-8\auto.cnf' to disk (OS errno 22 - Invalid argument [OS Error Code : 0x1e3])
2023-12-24T04:35:43.475757Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.

注意:auto.cnf文件确实存在格式正确的UUID(server-uuid=e61ff650-...)。

已尝试的排查步骤

  • 测试了两个MySQL 8版本:mysql-8.0.30-winx64和mysql-8.0.35-winx64,结果一致
  • 更换过Laragon默认my.ini和网上精简版配置文件,每次测试都从空的data目录开始
  • Laragon相关目录已加入系统Path环境变量

当前配置文件(my.ini)

[client]
#password=your_password
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=256M
max_allowed_packet=512M
table_open_cache=256
sort_buffer_size=1M
read_buffer_size=1M
read_rnd_buffer_size=4M
myisam_sort_buffer_size=64M
thread_cache_size=8

#secure-file-priv=""
explicit_defaults_for_timestamp=1
basedir="M:/laragon/bin/mysql/mysql-8.0.35-winx64"
datadir= "M:/laragon/data/mysql-8"
default_authentication_plugin=mysql_native_password

[mysqldump]
quick
max_allowed_packet=512M

初始化命令及完整输出

执行命令:

mysqld --initialize-insecure --console

完整输出:

2023-12-24T04:35:43.384530Z 0 [System] [MY-013169] [Server] M:\laragon\bin\mysql\mysql-8.0.35-winx64\bin\mysqld.exe (mysqld 8.0.35) initializing of server in progress as process 29828
mysqld: Can't sync file 'M:\laragon\data\mysql-8\auto.cnf' to disk (OS errno 22 - Invalid argument [OS Error Code : 0x1e3])
2023-12-24T04:35:43.475757Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.
2023-12-24T04:35:43.475814Z 0 [ERROR] [MY-013455] [Server] The newly created data directory M:\laragon\data\mysql-8\ by --initialize is unusable. You can remove it.
2023-12-24T04:35:43.475880Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-12-24T04:35:43.475989Z 0 [System] [MY-010910] [Server] M:\laragon\bin\mysql\mysql-8.0.35-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.35)  MySQL Community Server - GPL.

解决方案

  • 检查磁盘权限与文件系统
    确认M:\laragon\data\mysql-8目录权限:右键目录→属性→安全,确保当前用户拥有完全控制权限;同时检查磁盘M的属性,取消勾选“压缩此驱动器以节约磁盘空间”和“加密内容以便保护数据”,重启电脑后再尝试初始化。

  • 修正my.ini配置

    • 移除socket=/tmp/mysql.sock:Windows环境下MySQL不依赖Unix socket,该配置可能引发冲突
    • 去掉datadir后的空格:将datadir= "M:/laragon/data/mysql-8"改为datadir="M:\laragon\data\mysql-8"(Windows下建议使用反斜杠路径)
  • 以管理员身份执行命令
    打开CMD或PowerShell时选择“以管理员身份运行”,再执行初始化命令,避免权限不足导致的文件写入问题。

  • 排除杀毒软件干扰
    临时关闭Windows Defender或第三方杀毒软件的实时保护,或将M:\laragon目录加入信任列表,防止杀毒软件拦截MySQL的文件写入操作。

  • 手动生成UUID并初始化
    手动创建M:\laragon\data\mysql-8\auto.cnf文件,内容为:

    [auto]
    server-uuid=e61ff650-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    

    替换为合法UUID后,执行初始化命令;若仍报错,删除auto.cnf后重新执行初始化。


内容的提问来源于stack exchange,提问作者PeterN

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 15:07:20