Linux中[ERROR] --initialize specified but the data directory has files in it. Aborting.:

问题描述:

Linux中安装mysql,由于之前安装过,卸载过,卸载的不干净,再次安装,,在进行初始化密码的时候,出现了以下错误

2021-11-23T02:08:16.247240Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-23T02:08:16.248753Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2021-11-23T02:08:16.248780Z 0 [ERROR] Aborting

原因分析:

原因:旧版本的MySQL软件移除时没有删除原来的数据文件,即 /var/lib/mysql/路径下的内容。

解决方法:删除该路径下的所有内容,包括文件和文件夹。

[root@hadoop102 mysql]# rm -rf  /var/lib/mysql/

执行成功以后,初始化密码:

[root@hadoop102 opt]# mysqld --initialize --user=mysql
[root@hadoop102 opt]# cat /var/log/mysqld.log
2021-11-23T02:17:47.821574Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-23T02:17:47.988844Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-23T02:17:48.010498Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-23T02:17:48.066559Z 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: 8d49959d-4c03-11ec-be82-000c29bdc989.
2021-11-23T02:17:48.067296Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-23T02:17:48.067886Z 1 [Note] A temporary password is generated for root@localhost: UBX6u)ekR:kB

由于我的data中并没有保存任何数据,因此直接删除不会影响后续任务,但是!!!大家如果有数据的一定要先备份呀~


Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐