mysql安装报错,提示[ERROR] --initialize specified but the data directory has files in it.

mysql安装报错,提示[ERROR] --initialize specified but the data directory has files in it.

一、启动报错:

[root@CentOS7 mysql-5.7.27-1.el7.x86_64.rpm-bundle]# systemctl restart mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@CentOS7 mysql-5.7.27-1.el7.x86_64.rpm-bundle]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: deactivating (final-sigterm) (Result: exit-code)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3090 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 3067 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mysqld.service
           └─3093 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Nov 15 11:24:51 CentOS7.5 systemd[1]: mysqld.service holdoff time over, scheduling restart.
Nov 15 11:24:51 CentOS7.5 systemd[1]: Starting MySQL Server...
Nov 15 11:24:51 CentOS7.5 mysqld_pre_systemd[3067]: 2019-11-15T03:24:51.883600Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. P...etails).
Nov 15 11:24:51 CentOS7.5 mysqld_pre_systemd[3067]: 2019-11-15T03:24:51.889721Z 0 [ERROR] --initialize specified but the data directory has files ...borting.
Nov 15 11:24:51 CentOS7.5 mysqld_pre_systemd[3067]: 2019-11-15T03:24:51.889983Z 0 [ERROR] Aborting
Nov 15 11:24:52 CentOS7.5 systemd[1]: mysqld.service: control process exited, code=exited status=1
Hint: Some lines were ellipsized, use -l to show in full.
[root@CentOS7 mysql-5.7.27-1.el7.x86_64.rpm-bundle]# journalctl -xe
-- 
-- Unit mysqld.service has begun starting up.
Nov 15 11:25:09 CentOS7.5 mysqld_pre_systemd[3437]: 2019-11-15T03:25:09.609186Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use -
Nov 15 11:25:09 CentOS7.5 mysqld_pre_systemd[3437]: 2019-11-15T03:25:09.614965Z 0 [ERROR] --initialize specified but the data directory has files in it. Abor
Nov 15 11:25:09 CentOS7.5 mysqld_pre_systemd[3437]: 2019-11-15T03:25:09.615036Z 0 [ERROR] Aborting
Nov 15 11:25:10 CentOS7.5 mysqld[3460]: Initialization of mysqld failed: 0
Nov 15 11:25:10 CentOS7.5 systemd[1]: mysqld.service: control process exited, code=exited status=1
Nov 15 11:25:11 CentOS7.5 systemd[1]: Failed to start MySQL Server

在这里插入图片描述

二、解决办法:

1.查看配置文件中的datadir的路径

cat /etc/my.cnf

[root@CentOS7 mysql-5.7.27-1.el7.x86_64.rpm-bundle]# cat /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

2.清空/var/lib/mysql文件夹下的内容

cd /var/lib/mysql

[root@CentOS7 mysql-5.7.27-1.el7.x86_64.rpm-bundle]# cd /var/lib/mysql
[root@CentOS7 mysql]# ll
total 122924
-rw-r----- 1 mysql mysql       56 Nov 15 11:24 auto.cnf
-rw------- 1 mysql mysql     1675 Nov 15 11:20 ca-key.pem
-rw-r--r-- 1 mysql mysql     1107 Nov 15 11:20 ca.pem
-rw-r--r-- 1 mysql mysql     1107 Nov 15 11:20 client-cert.pem
-rw------- 1 mysql mysql     1679 Nov 15 11:20 client-key.pem
-rw-r----- 1 mysql mysql      217 Nov 15 11:26 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Nov 15 11:26 ibdata1
-rw-r----- 1 mysql mysql 50331648 Nov 15 11:26 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Nov 15 11:24 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Nov 15 11:26 ibtmp1
srwxrwxrwx 1 mysql mysql        0 Nov 15 11:26 mysql.sock
-rw------- 1 mysql mysql        5 Nov 15 11:26 mysql.sock.lock
-rw------- 1 mysql mysql     1679 Nov 15 11:20 private_key.pem
-rw-r--r-- 1 mysql mysql      451 Nov 15 11:20 public_key.pem
-rw-r--r-- 1 mysql mysql     1107 Nov 15 11:20 server-cert.pem
-rw------- 1 mysql mysql     1679 Nov 15 11:20 server-key.pem

3.删除里面的数据

rm -rf ./*

[root@CentOS7 mysql]# rm -rf ./*
[root@CentOS7 mysql]# ll
total 122892
-rw-r----- 1 mysql mysql       56 Nov 15 11:26 auto.cnf
-rw-r----- 1 mysql mysql 12582912 Nov 15 11:26 ibdata1
-rw-r----- 1 mysql mysql 50331648 Nov 15 11:26 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Nov 15 11:26 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Nov 15 11:26 ibtmp1
drwxr-x--- 2 mysql mysql     4096 Nov 15 11:26 mysql
drwxr-x--- 2 mysql mysql     4096 Nov 15 11:26 performance_schema

4.重新启动

systemctl restart mysqld

[root@CentOS7 mysql]# systemctl restart mysqld
[root@CentOS7 mysql]# 

数据库即正常运行了

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值