mysql入坑之路(6)mysql 启动报错 [ERROR] --initialize specified but the data directory has files in it. Aborting.
参考文档:
https://www.cnblogs.com/baixing/articles/14771099.html
1、查看系统日志
完整日志:
2022-09-15T03:08:31.411273Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-09-15T03:08:31.412201Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2022-09-15T03:08:31.412224Z 0 [ERROR] Aborting
------译文
2022-09-15T03:08:31.411273Z 0 [警告] 带有隐式 DEFAULT 值的 TIMESTAMP 已弃用。 请使用 --explicit_defaults_for_timestamp 服务器选项(有关详细信息,请参阅文档)。
2022-09-15T03:08:31.412201Z 0 [错误] -- 指定初始化,但数据目录中有文件。 中止。
2022-09-15T03:08:31.412224Z 0 [错误] 中止
2、发现mysql启动错误日志关键句
[ERROR] --initialize specified but the data directory has files in it. Aborting.
[错误] -初始化指定,但数据目录中有文件。中止
错误解释:之前可能已经启动过mysql导致mysql数据目录中存在文件
3、解决方法:将数据目录下已存在的文件全部删除。
1.查询mysql数据目录
[root@test mysql]# cat /etc/my.cnf | grep datadir #过滤出mysql数据目录
datadir=/var/lib/mysql
2.删除数据目录下文件
[root@test mysql]# rm -rf /var/lib/mysql/*
3.重新启动mysql
systemctl restart mysqld
过滤删除快捷命令(快速解决问题)
rm -rf `cat /etc/my.cnf | grep datadir | awk -F= '{print $2}'`
4、初始化数据库:
换掉有数据存在的目录,或者清空目录
初始化-新目录mysql6-back
/home/demo-8888/mysql5.7-37/bin/mysqld --user=mysql --basedir=/home/demo-8888/mysql5.7-37 --datadir=/home/demo-8888/mysql6-back --initialize
输出:
2022-09-15T03:18:20.644334Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-09-15T03:18:20.773901Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-09-15T03:18:20.797967Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-09-15T03:18:20.853310Z 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: 0cded9c4-34a5-11ed-80fe-5414f3ddfa95.
2022-09-15T03:18:20.854715Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-09-15T03:18:21.430594Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-09-15T03:18:21.430604Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-09-15T03:18:21.430975Z 0 [Warning] CA certificate ca.pem is self signed.
2022-09-15T03:18:21.519692Z 1 [Note] A temporary password is generated for root@localhost: !5xLUbM;mi5q