欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2024-03-14 17:10:19
...

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

一、启动报错:

[aaa@qq.com 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.
[aaa@qq.com 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.
[aaa@qq.com 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

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

二、解决办法:

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

cat /etc/my.cnf

[aaa@qq.com 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

[aaa@qq.com mysql-5.7.27-1.el7.x86_64.rpm-bundle]# cd /var/lib/mysql
[aaa@qq.com 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 ./*

[aaa@qq.com mysql]# rm -rf ./*
[aaa@qq.com 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

[aaa@qq.com mysql]# systemctl restart mysqld
[aaa@qq.com mysql]# 

数据库即正常运行了