黑猴子的家:MySQL5.7 启动报错:initialize specified but the data directory has files in it. Aborting.

MySQL5.7 启动报错:initialize specified but the data directory has files in it. Aborting.

1、mysql 5.7 启动

[root@hadoop102 ~]# systemctl start mysqld
Job for mysqld.service failed because the control process exited \
with error code. See 
"systemctl status mysqld.service" and "journalctl -xe" for details

2、mysql 5.7 查看启动失败详情

[root@hadoop102 ~]# systemctl status mysqld
[root@hadoop102 ~]# journalctl -xe
Oct 23 10:50:55 bignode2 mysqld_pre_systemd[9423]: 2018-10-23T02:50:55.072038Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see d
Oct 23 10:50:55 bignode2 mysqld_pre_systemd[9423]: 2018-10-23T02:50:55.074671Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
Oct 23 10:50:55 bignode2 mysqld_pre_systemd[9423]: 2018-10-23T02:50:55.074705Z 0 [ERROR] Aborting
Oct 23 10:50:55 bignode2 mysqld[9447]: Initialization of mysqld failed: 0
Oct 23 10:50:55 bignode2 systemd[1]: mysqld.service: control process exited, code=exited status=1
Oct 23 10:50:57 bignode2 systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has failed.
-- 
-- The result is failed.
Oct 23 10:50:57 bignode2 systemd[1]: Unit mysqld.service entered failed state.
 ESCOD
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has begun starting up.

3、详情中,这句很重要

initialize specified but the data directory has files in it. Aborting.

4、查看mysql5.7 数据存储目录

[root@hadoop102 ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#default-storage-engine=innodb
#collation-server=utf8_general_ci
#init-connect='SET NAMES utf8'
#character-set-server=utf8
#validate_password_policy=0
#validate_password_length=1
#validate_password=off
#port=3306

5、查看 /var/lib/mysql 目录是否确实有数据

[root@hadoop102 ~]# cd /var/lib/
[root@hadoop102 lib]# ls mysql/

6、备份mysql数据

[root@hadoop102 lib]# pwd
/var/lib/
[root@hadoop102 lib]# mv mysql mysqlbak
[root@hadoop102 lib]# mkdir mysql

7、重新启动 mysql 5.7 并查看状态

[root@hadoop102 ~]# systemctl start mysqld
[root@hadoop102 ~]# systemctl status mysqld

你可能感兴趣的:(MySql)