Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql initializing databsase error -- initialize specified but the data directory has files in it. aborting #290

Closed
ramizrshaik opened this issue Apr 27, 2017 · 27 comments

Comments

@ramizrshaik
Copy link

hi

this is my compose file

version: '2'

services:
sonarqube:
image: sonarqube:5.1.2
ports:
- "9000:9000"
restart: always
depends_on:
- "db"
environment:
- "SONARQUBE_JDBC_USERNAME="
- "SONARQUBE_JDBC_PASSWORD="
- "SONARQUBE_JDBC_URL=jdbc:mysql://db:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false"
volumes:
- /media/windows-share/docker-sonar-volume/sonar/data:/opt/sonarqube/data
- /media/windows-share/docker-sonar-volume/sonar/conf:/opt/sonarqube/conf
- /media/windows-share/docker-sonar-volume/sonar/extensions:/opt/sonarqube/extensions

db:
image: mysql:latest
restart: always
environment:
- "MYSQL_ROOT_PASSWORD="
- "MYSQL_DATABASE="
- "MYSQL_USER="
- "MYSQL_PASSWORD="
volumes:
- /media/windows-share/docker-sonar-volume/var/lib/mysql:/var/lib/mysql/data

i tried chaging the volume path, but mysql isn't persisting the exisiting data. or it is showing this initialization error. please help me out i stuck with this issue from 3 days. also i am attaching my screenshot error.
i tried emptying the directory too but no luck.

2017-04-27_11-38-53

@bsb20
Copy link

bsb20 commented Apr 27, 2017

The issue is that the check to see if the $DATADIR exists is wrong in the docker-entrypoint.sh script, I'll submit my fix

@ramizrshaik
Copy link
Author

Hi, really appreciate for the reply. i am new to this whole docker and terminal using stuff. can you please explain a little bit in detail how to resolve this. TIA

@tianon
Copy link
Member

tianon commented Apr 27, 2017

I think

  - /media/windows-share/docker-sonar-volume/var/lib/mysql:/var/lib/mysql/data

should be instead

  - /media/windows-share/docker-sonar-volume/var/lib/mysql:/var/lib/mysql

(just /var/lib/mysql as the mount target, which is the defined VOLUME of this image -- see

VOLUME /var/lib/mysql
)

@ramizrshaik
Copy link
Author

changed it to the path .. still same error

@ltangvald
Copy link
Collaborator

ltangvald commented Apr 28, 2017

The entrypoint script checks if DATADIR/mysql exists. If not, it runs --initialize, but if DATADIR/ contains any files other than ones starting with . or specified with --ignore-db-dir, --initialize will fail with that error message.

So the directory you map to :/var/lib/mysql should either contain an existing MySQL database or be completely empty

@ramizrshaik
Copy link
Author

@ltangvald mysql directory is clean no files in it. here i am attaching the screen shot

2017-04-28_10-25-40

@yosifkit
Copy link
Member

I am confused. You did ls on /var/lib/mysql in your vagrant VM, but what you are mounting to the container is /media/windows-share/docker-sonar-volume/var/lib/mysql.

@ramizrshaik
Copy link
Author

Hi @yosifkit .. he (@ltangvald ) mentioned about right side of the ":" i.e :/var/lib/mysql thats why i showed ls on that.

if i ls on '/media/windows-share/docker-sonar-volume/var/lib/mysql' this will show me all the exisiting the sonar data. thats my requirement; so, i pointed mysql to that host path to start with already existing sonar data.

@yosifkit
Copy link
Member

The right side, ie /var/lib/mysql, is relative to the file system in the container, not the VM. So using your compose file will mount the /media/windows-share/docker-sonar-volume/var/lib/mysql directory as /var/lib/mysql in the container, so its contents are very relevant. It should either be empty so that starting the MySQL container will fill it with its initial database files, or it should be already populated by a previous MySQL server (the MySQL server major/minor version, like "5.7", should be the same, though there are ways to upgrade between versions).

It should look something like the following. The database file that we look for in the entrypoint script to determine if the folder already contains an initialized database is mysql.

root@39ae6038c8e2:/# ls -l /var/lib/mysql
total 188476
-rw-r----- 1 mysql mysql       56 Apr 28 23:04 auto.cnf
-rw------- 1 mysql mysql     1679 Apr 28 23:04 ca-key.pem
-rw-r--r-- 1 mysql mysql     1074 Apr 28 23:04 ca.pem
-rw-r--r-- 1 mysql mysql     1078 Apr 28 23:04 client-cert.pem
-rw------- 1 mysql mysql     1679 Apr 28 23:04 client-key.pem
-rw-r----- 1 mysql mysql     1321 Apr 28 23:04 ib_buffer_pool
-rw-r----- 1 mysql mysql 50331648 Apr 28 23:04 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Apr 28 23:04 ib_logfile1
-rw-r----- 1 mysql mysql 79691776 Apr 28 23:04 ibdata1
-rw-r----- 1 mysql mysql 12582912 Apr 28 23:04 ibtmp1
drwxr-x--- 2 mysql mysql     4096 Apr 28 23:04 mysql
drwxr-x--- 2 mysql mysql     4096 Apr 28 23:04 performance_schema
-rw------- 1 mysql mysql     1675 Apr 28 23:04 private_key.pem
-rw-r--r-- 1 mysql mysql      451 Apr 28 23:04 public_key.pem
-rw-r--r-- 1 mysql mysql     1078 Apr 28 23:04 server-cert.pem
-rw------- 1 mysql mysql     1675 Apr 28 23:04 server-key.pem
drwxr-x--- 2 mysql mysql    12288 Apr 28 23:04 sys

@ramizrshaik
Copy link
Author

i copied my previous sonar db data into the host directory. if i ls on /media/windows-share/var/lib/mysql then it will be like below screen shot.
2017-04-29_23-34-19

may be that why i am getting this error. can you please tell me what shall i do to make my mysql to pick that existing sonar data while starting up.

@ramizrshaik
Copy link
Author

thanks for all the suggestions .. :)

@ltangvald
Copy link
Collaborator

Those are sql scripts, not a database. Are those the output from a dump operation you want to restore to a docker database?

@ltangvald
Copy link
Collaborator

If those are dump files that can be used to restore the database, you might be able to instead map that directory to /docker-entrypoint-initdb.d/ (but I'm not sure if the ordering will be correct).

The contents of var/lib/mysql should be as yosifkit posted above

@ramizrshaik
Copy link
Author

@ltangvald yes those from mysql dump. thanks for the suggestion i will try that option

@saifrehman15
Copy link

I have same issue but no solution works.
$ docker logs cyrano-project_mysql_1
Initializing database
2018-08-06T06:36:48.947657Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-08-06T06:36:48.947796Z 0 [ERROR] Aborting

@brokolja
Copy link

brokolja commented Sep 7, 2018

The Error: "initialize specified but the data directory has files in it" could happen if your system is probably out of disk space. Mysql is writing partial data to test the system. If you see a file: "ibdata1" in your volume this test failed. So check if you have free disc space, delete the file: "ibdata" or remove the volume and start/restart again...

@ghost
Copy link

ghost commented Nov 7, 2018

remove all files in {path-to-mysql}\data directory and run:
mysqld --initialize-insecure --basedir={path-to-mysql}\mysql --datadir={path-to-mysql}\data --console

@rqc
Copy link

rqc commented Jan 30, 2019

I just ran into this issue using the mysql docker image on my local Mac OS environment. As @koljakutschera mentioned, this seems to be an issue with space. I ran docker system prune --volumes on my system, which freed 45.86GB of space, solving the issue. Be advised that this is a destructive command, I only tested it on my local dev environment.

@apigban
Copy link

apigban commented May 7, 2019

@rqc It worked! What I don't understand is why it worked, I had 12GB free, when I did docker system prune --volumes, recovered 24GB

But yeah it worked!

@lispmind
Copy link

lispmind commented Aug 3, 2019

I just ran into this issue using the mysql docker image on my local Mac OS environment. As @koljakutschera mentioned, this seems to be an issue with space. I ran docker system prune --volumes on my system, which freed 45.86GB of space, solving the issue. Be advised that this is a destructive command, I only tested it on my local dev environment.

docker system prune --volumes fix my problem

@tonyg4864
Copy link

@rqc Why does docker system prune --volumes work when you already had 12GB of free space. How much space is needed to start this database up ?

@rqc
Copy link

rqc commented Sep 1, 2019

Hi, sorry for the late reply. docker can leave dangling data from volumes. If you look at the docker prune documentation it says:

By default, volumes are not removed to prevent important data from being deleted if there is currently no container using the volume. Use the --volumes flag when running the command to prune volumes as well:

@dinesh0985
Copy link

docker system prune --volumes worked !!

@anisjonischkeit
Copy link

@apigban @tonyg4864 There's a difference between how much disk space you have and how much disk space docker is still allowed to access. On Mac you can see how much Docker can use by clicking the docker icon in the top bar -> preferences -> resources:

Screenshot 2020-07-09 at 13 56 21

@oli-ver
Copy link

oli-ver commented Aug 22, 2020

In my case the issue occured when mounting a directory from my c drive when using Windows Subsystem for Linux 2 (WSL2). Mounting a directory from my user directory of the wsl linux system worked fine.

If I understand correctly this seems to be a known issue in docker for windows occurring for named volumes: docker/for-win#4812

@ernest-kr
Copy link

I am on Mac OS and is brand new but I had the same issue

docker system prune --volumes worked

Does any one have idea what this does

@tianon
Copy link
Member

tianon commented Aug 28, 2020

That's deleted all unused Docker volumes on your system (and containers, and untagged images); https://docs.docker.com/engine/reference/commandline/system_prune/

@docker-library docker-library locked as resolved and limited conversation to collaborators Aug 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests