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

[error] – initialize specified but the data directory has files in it. About.:

Problem Description:

MySQL is installed in Linux. Because it has been installed and uninstalled before, the uninstallation is not clean. When installing again, the following error occurs when initializing the password

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

Cause analysis:

reason: the old version of MySQL software does not delete the original data file, that is, the content under the path/var/lib/MySQL/

Solution: delete all contents under the path, including files and folders.

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

After successful execution, initialize the password:

[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

Because there is no data saved in my data, direct deletion will not affect subsequent tasks, but!!! If you have data, you must back it up first~


Read More: