报错信息

2025-02-27T06:48:16.626686Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-27T06:48:16.626803Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.41)  MySQL Community Server - GPL.
2025-02-27 14:49:08+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.41-1.el9 started.
2025-02-27 14:49:08+08:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-02-27 14:49:08+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.41-1.el9 started.
2025-02-27 14:49:08+08:00 [Note] [Entrypoint]: Initializing database files
2025-02-27T06:49:08.570574Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2025-02-27T06:49:08.570653Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.41) initializing of server in progress as process 80
2025-02-27T06:49:08.571942Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-02-27T06:49:08.571948Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-02-27T06:49:08.572008Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-27T06:49:08.572127Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.41)  MySQL Community Server - GPL.
2025-02-27 14:50:09+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.41-1.el9 started.
2025-02-27 14:50:09+08:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-02-27 14:50:09+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.41-1.el9 started.
2025-02-27 14:50:09+08:00 [Note] [Entrypoint]: Initializing database files
2025-02-27T06:50:09.301217Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2025-02-27T06:50:09.301295Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.41) initializing of server in progress as process 79
2025-02-27T06:50:09.302566Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-02-27T06:50:09.302572Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-02-27T06:50:09.302617Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-27T06:50:09.302737Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.41)  MySQL Community Server - GPL.
[root@VM-12-15-centos docker-compose]# 

从日志中可以看到,MySQL 在初始化时遇到了问题,具体错误信息是:

[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
[ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.

这意味着 MySQL 在初始化时发现数据目录 /var/lib/mysql/ 中已经存在文件,因此无法继续初始化。通常,这种情况发生在你尝试重新初始化 MySQL,但数据目录中仍然保留着之前的数据文件。

解决方法

  1. 备份数据(如果数据重要):
    在删除数据目录中的文件之前,确保你已经备份了重要的数据。你可以将 /var/lib/mysql/ 目录中的文件复制到其他位置进行备份。

    cp -r /var/lib/mysql /path/to/backup
    
  2. 清理数据目录
    如果你确定不需要这些数据,或者已经备份了数据,可以删除 /var/lib/mysql/ 目录中的所有文件。

    rm -rf /var/lib/mysql/*
    
  3. 重新初始化 MySQL
    清理完数据目录后,重新启动 MySQL 服务,它会自动重新初始化数据目录。

    systemctl start mysql
    

    或者,如果你使用的是 Docker,重新启动容器:

    docker-compose up -d
    
  4. 检查 MySQL 是否正常运行
    重新启动后,检查 MySQL 是否正常运行:

    systemctl status mysql
    

    或者查看容器日志:

    docker-compose logs mysql
    

注意事项

  • 数据安全:在执行删除操作之前,务必确保你已经备份了重要数据,以免造成数据丢失。

  • 权限问题:确保 MySQL 用户(通常是 mysql)对 /var/lib/mysql/ 目录有正确的读写权限。

    chown -R mysql:mysql /var/lib/mysql
    
Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐