Pay C.
Pay C.

Reputation: 1108

Initializing mysql directory error

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.

Upvotes: 36

Views: 125767

Answers (13)

Vladyslav Tolosiuk
Vladyslav Tolosiuk

Reputation: 29

What helped me to resolve the error is trying to remove the volume of the corresponding API that I was using:

docker volume rm {{volume_name}}

After that, I was able to start MySQL Container Hope this helps

Upvotes: -1

gabrieloliveira
gabrieloliveira

Reputation: 570

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.

Upvotes: 1

FantomX1
FantomX1

Reputation: 1711

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).

Upvotes: 0

spirito_libero
spirito_libero

Reputation: 1322

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

Upvotes: 0

Karan Singh
Karan Singh

Reputation: 1164

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

Upvotes: 4

Thiago G. Alves
Thiago G. Alves

Reputation: 1399

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

Upvotes: 19

Turan Zamanlı
Turan Zamanlı

Reputation: 3926

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

Upvotes: -3

nur zazin
nur zazin

Reputation: 1188

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.

Upvotes: 4

why
why

Reputation: 61

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:

Upvotes: 2

Abdallah Okasha
Abdallah Okasha

Reputation: 2139

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.

Upvotes: 0

Ashik Ahmed
Ashik Ahmed

Reputation: 142

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

Upvotes: 9

Ghasem Pahlavan
Ghasem Pahlavan

Reputation: 721

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.

Upvotes: 6

Eugene Lisitsky
Eugene Lisitsky

Reputation: 12845

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.

Upvotes: 18

Related Questions