31

I checked this page: http://dev.mysql.com/doc/refman/5.7/en/mysql-install-db.html

mysql_install_db is removed, however, when I use mysqld --initialize. It promotes these errors and warning.

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

[ERROR] --initialize specified but the data directory has files in it. Aborting.
[ERROR] Aborting

The first one can be ignored according to this:How to enable explicit_defaults_for_timestamp?

I don't know how to solve the second problem.

Community
  • 1
  • 1
Pay C.
  • 1,048
  • 1
  • 13
  • 20

12 Answers12

17

Pls, read error carefully:

[ERROR] --initialize specified but the data directory has files in it. Aborting.

Your directory is not empty. You have to remove all the contents of it or choose another one.

Eugene Lisitsky
  • 12,113
  • 5
  • 38
  • 59
  • 26
    how about if it was really empty and it looks like mysql wrote those files and says that to me, it's so ironic but im experiencing it. LOL – rrw Apr 25 '17 at 02:16
  • 2
    using docker-compose, I solved it by following this https://github.com/docker-library/mysql/issues/219 – rrw Apr 25 '17 at 02:41
  • 8
    I don't know which directory is has files in it. Do you know what directory that's mean? – Rohman HM Jul 17 '17 at 04:01
  • It depends on OS distrib you use. Typically for Ubuntu it is `/var/lib/mysql`, but may vary. Better to google what directory is used in your case. – Eugene Lisitsky Jul 17 '17 at 09:19
  • Which directory is this referring to specifically? – crmpicco Jul 24 '17 at 14:26
  • It must be said to DO NOT remove data without doing BACKUP to another folder!! – Andre Figueiredo Feb 15 '18 at 23:01
  • Sure, there stated "or choose another directory". – Eugene Lisitsky Feb 16 '18 at 07:53
  • Why would we need to remove files in it if it is intended to be persisted? Can someone help me – iamjc015 Jul 30 '18 at 05:38
  • That depends. If you have good installation with data files in it, then you don't need to make `--initialize`. It is used for new fresh installations. – Eugene Lisitsky Jul 30 '18 at 07:40
  • 5
    the initialize is not intented and is coming from systemd or anywhere. This solution is not a solution. The problem is not the data, but the nebulous initialize option that no-one wants. mysqld should start with the data it has, not initialize new data. Your solution actually consists of just "read the error message" which everyone surely has and understood. – sgohl Jan 14 '19 at 13:27
  • please try this. its worked for me : volumes: - /your-empty-folder:/var/lib/mysql – nur zazin Feb 22 '20 at 16:36
  • @rrw what helped to fix that issue of complaining about own created data existing, is for example that you have the option `innodb_force_recovery = 3 ` specified in your config, which must not be there before emptying that folder. – FantomX1 Aug 16 '21 at 14:04
  • Just delete the mysql data directory. In my case on Mac it was /opt/homebrew/var/mysql. If you want to find out your data directory you can install 'locate' command and then use it to search 'mysql'. Your databases of any earlier mysql installation will be gone. – zafar142003 Sep 15 '22 at 11:43
15

I had this issue with Kubernetes and MySQL 5.7 as well.

Adding the suggestion from yosifki to my container's definition got things working.

A new ext4 disk partition is not usually empty; there is a lost+found directory, which mysql is known to choke on. You could try adding --ignore-db-dir=lost+found to the CMD to know for sure (from mysql docs)

Here's an extract of my working YAML definition:

name: mysql-master
image: mysql:5.7
args:
  - "--ignore-db-dir=lost+found"

And here, a docker-compose snippet for better clarify:

version: '3'
services:
  mysql-master:
    image: mysql:5.7
    command: [--ignore-db-dir=lost+found]
    environment:
      - MYSQL_ROOT_PASSWORD=root
Thiago G. Alves
  • 1,202
  • 1
  • 14
  • 24
9

I faced the sample problem. i renamed the container directory from

/var/lib/mysql

to

/var/lib/minesql or some different name

. Now the container is started.

Previous Command:

docker container run --name=mysql -d -e MYSQL_ROOT_PASSWORD=abc1234 -e MYSQL_DATABASE=sample -e MYSQL_USER=ashik -e MYSQL_PASSWORD=abc123 -v mysql_volume:/var/lib/mysql mysql

Working Command:

docker container run --name=mysql -d -e MYSQL_ROOT_PASSWORD=abc1234 -e MYSQL_DATABASE=sample -e MYSQL_USER=ashik -e MYSQL_PASSWORD=abc123 -v mysql_volume:/var/lib/minesql mysql

enter image description here

Ashik Ahmed
  • 142
  • 1
  • 11
6

Its usually means your data directory is not empty. If you remove or rename the data directory and the problem still exist, check your config file /etc/my.cnf and delete validate_password_policy variable in the initialize step. after starting the server you can set this variable to any things you want.

Ghasem Pahlavan
  • 661
  • 9
  • 20
  • 2
    Which directory is my "data directory"? It would be useful if MySQL output the directory it is checking in to give you a help. – crmpicco Jul 24 '17 at 14:27
  • you can see your datadir path using this command: `mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name LIKE "datadir"'` – Ghasem Pahlavan Jul 25 '17 at 11:04
  • also, the default MySQL data directory is `/var/lib/mysql`. you can find data dir path from variables in `/etc/my.cnf` or files in `/etc/my.cnf.d/`. – Ghasem Pahlavan Jul 25 '17 at 11:15
3

just remove /data directory. this is worked for me :

as simple like this :

image: mysql:5.7
volumes:
  - ./db:/var/lib/mysql

and make sure your "./db" directory is empty.

nur zazin
  • 1,018
  • 13
  • 13
3

Fixed it by: rm -rf /usr/local/Cellar/mysql and rm -rf /usr/local/var/mysql and reinstalling mysql again.

Got another error, which was fixed by: Warning: The post-install step did not complete successfully, When trying to install mysql using brew in Mac OS High Sierra

Karan Singh
  • 1,114
  • 1
  • 13
  • 30
2

If you're running Docker Desktop for Mac, this could be because Docker.qcow2 has exceeded it's maximum size. This file has a default size of 64GB. You can resize it, or for a more drastic solution, delete it:

rm ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

References:

why
  • 61
  • 1
  • 1
  • 4
0

In my case the solution was to edit volume directory in my docker-compose.yml

from:

image: mysql:5.6
    volumes:
      - ./db:/var/lib/mysql/data

To

image: mysql:5.6
    volumes:
      - ./db_data:/var/lib/mysql/data

And run again sudo docker-compose build

sudo docker-compose up

And then you may need to run migrate sudo docker-compose run web rake db:create for my Rails app.

Abdallah Okasha
  • 1,879
  • 17
  • 20
0

I had similar issue, but no mysql folder inside the /usr/local.

In my case mysql was located inside the /usr/local/var

so rm -rf /usr/local/var/mysql fixed the problem

spirito_libero
  • 1,206
  • 2
  • 13
  • 21
0

Proceed as suggested in the @Eugene Lisitsky's answer,= erasing the /var/lib/mysql directory, the mysql directory contents. But do not keep the option innodb_force_recovery present in the /etc/my.cnf configuration file (or some such other alternative configuration I suppose, which would prevent initialization/installation due to own files).

FantomX1
  • 1,577
  • 2
  • 15
  • 23
0

Increase locked memory limit with ulimit -l

Read bellow to see more details about this approach:

I have this problem with docker. On this specific server, we run more than 100 containers and about 30 MySQL containers.

After a long search and trying some things I see that the problem is related to having many docker containers, but I did not find any limit.

Even with no volumes the error appears, so nothing related to having some file in the directory.

After 3 days, I test replace MySQL with the MariaDB image, and finally, we have a decent message for the error.

The logs say that InnoDB can't be initialized because the system does not have a sufficient memory-locked limit. A system limit that can be read or set with limit -l.

Ps: To keep ulimit settings after restart, edit /etc/security/limits.conf file.

So, after that, I increase the limit to double the current value and receive now a more clear log from MySQL with the message:

Cannot initialize AIO sub-system

After that, I have to increase the aio-max-nr value from the system. To read the current value of aio-max-nr, execute cat /proc/sys/fs/aio-max-nr.

To set a new value, execute: sudo sysctl -w fs.aio-max-nr=524288 and to keep the value when restarting, edit the /etc/sysctl.conf with the new value.

After editing these settings you will run the MySQL container again. But remember, now you have to reset or clear the /var/lib/mysql folder to run without the first error.

gabrieloliveira
  • 560
  • 3
  • 10
-2

Disable SElinux.

Setenforce 0

Also create log directory in /var/logs/ mysql folder It have to mysql user owner

cd /var/log/
mkdir mysql
chown -R mysql:mysql mysql/

then change log direcotry in /etc/my.cnf

Turan Zamanlı
  • 3,828
  • 1
  • 15
  • 23