sameersbn / docker-mysql

A Dockerfile that installs a mysql server
MIT License
246 stars 174 forks source link

Restart mysql container report error messages: Could not connect to mysql server. Aborting... #16

Open fye opened 9 years ago

fye commented 9 years ago

I restart my mysql containers, according to the 'docker logs - tf mysql' command to check the log information to quote the following error:

Could not connect to mysql server. Aborting...

Could you tell me what could be the cause?

sameersbn commented 9 years ago

@fye can you provide the command sequence to reproduce this?

fye commented 9 years ago

Do you mean this:

[root@localhost mysql]# docker start confluence-mysql confluence-mysql [root@localhost mysql]# docker logs -tf confluence-mysql 2015-01-13T09:12:12.216443258Z Installing database... 2015-01-13T09:12:12.439014228Z Starting MySQL server... 2015-01-13T09:12:12.446440769Z Waiting for database server to accept connections... 2015-01-13T09:12:13.452028661Z Waiting for database server to accept connections... 2015-01-13T09:12:14.459716198Z Creating debian-sys-maint user... 2015-01-13T09:12:17.496668542Z Creating database "confluence"... 2015-01-13T09:12:17.502923775Z Granting access to database "confluence" for user "avatar"... 2015-01-13T09:12:17.508483085Z Creating database "jira"... 2015-01-13T09:12:17.514083029Z Granting access to database "jira" for user "avatar"... 2015-01-13T09:12:18.701941303Z 150113 09:12:18 mysqld_safe Logging to syslog. 2015-01-13T09:12:18.724363686Z 150113 09:12:18 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2015-02-02T10:54:53.951695796Z Creating database "confluence"... 2015-02-02T10:54:53.965155280Z Granting access to database "confluence" for user "avatar"... 2015-02-02T10:54:53.973363183Z Creating database "jira"... 2015-02-02T10:54:53.980243010Z Granting access to database "jira" for user "avatar"... 2015-02-02T10:54:55.245926074Z 150202 10:54:55 mysqld_safe Logging to syslog. 2015-02-02T10:54:55.277776529Z 150202 10:54:55 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2015-02-02T11:21:41.431041926Z 150202 11:21:41 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 2015-02-02T11:22:17.309403750Z Creating database "confluence"... 2015-02-02T11:22:17.324054024Z Granting access to database "confluence" for user "avatar"... 2015-02-02T11:22:17.331364575Z Creating database "jira"... 2015-02-02T11:22:17.338595375Z Granting access to database "jira" for user "avatar"... 2015-02-02T11:22:18.607737642Z 150202 11:22:18 mysqld_safe Logging to syslog. 2015-02-02T11:22:18.640158280Z 150202 11:22:18 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2015-02-02T11:22:42.517884542Z /usr/bin/mysqladmin: connect to server at 'localhost' failed 2015-02-02T11:22:42.517884542Z error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' 2015-02-02T11:22:42.517884542Z Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists! 2015-02-02T11:22:42.527687703Z /usr/bin/mysqladmin: connect to server at 'localhost' failed 2015-02-02T11:22:42.527687703Z error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' 2015-02-02T11:22:42.527687703Z Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists! 2015-02-02T11:22:42.601418136Z 150202 11:22:42 mysqld_safe Number of processes running now: 1 2015-02-02T11:22:42.662053936Z 150202 11:22:42 mysqld_safe mysqld process hanging, pid 758 - killed 2015-02-02T11:22:42.679482017Z 150202 11:22:42 mysqld_safe mysqld restarted 2015-02-02T11:32:37.917315362Z Creating database "confluence"... 2015-02-02T11:32:37.950214843Z Granting access to database "confluence" for user "avatar"... 2015-02-02T11:32:37.957583327Z Creating database "jira"... 2015-02-02T11:32:37.965457597Z Granting access to database "jira" for user "avatar"... 2015-02-02T11:32:39.233940874Z 150202 11:32:39 mysqld_safe Logging to syslog. 2015-02-02T11:32:39.265770639Z 150202 11:32:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2015-02-03T10:24:55.139419323Z 150203 10:24:55 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 2015-02-03T10:31:56.930375915Z Creating database "confluence"... 2015-02-03T10:31:56.946272193Z Granting access to database "confluence" for user "avatar"... 2015-02-03T10:31:56.953889196Z Creating database "jira"... 2015-02-03T10:31:56.960836520Z Granting access to database "jira" for user "avatar"... 2015-02-03T10:32:01.224282443Z 150203 10:32:01 mysqld_safe Logging to syslog. 2015-02-03T10:32:01.256111048Z 150203 10:32:01 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2015-06-18T17:12:06.065751830Z Could not connect to mysql server. Aborting... 2015-06-18T17:18:26.707323167Z Could not connect to mysql server. Aborting... 2015-06-19T09:46:11.850905456Z Could not connect to mysql server. Aborting... 2015-06-19T11:45:12.999241292Z Could not connect to mysql server. Aborting... 2015-06-19T11:47:08.912690325Z Could not connect to mysql server. Aborting... 2015-06-19T12:02:14.128367569Z Could not connect to mysql server. Aborting... 2015-06-19T12:24:57.215986423Z Could not connect to mysql server. Aborting... [2015-06-24T01:58:01.427990414Z] Could not connect to mysql server. Aborting... [root@localhost mysql]#

sameersbn commented 9 years ago

@fye the complete docker run command would be helpful, you can mask out the passwords if any.

I used the following

docker run -it --name=mysql \
  --env='DB_USER=avatar' --env='DB_PASS=password' --env='DB_NAME=jira,confluence' \
  sameersbn/mysql

No problems seen with repeatedly running..

docker stop mysql
docker start mysql
fye commented 9 years ago

sorry, I misunderstand. This is my command:

mkdir -p /opt/mysql/data2 sudo chcon -Rt svirt_sandbox_file_t /opt/mysql/data2

docker run --name confluence-mysql2 -d \ -p 3307:3306 \ -e 'DB_USER=avatar' -e 'DB_PASS=avatar' -e 'DB_NAME=confluence,jira' \ -v /opt/mysql/data2:/var/lib/mysql sameersbn/mysql:latest

fye commented 9 years ago

one more descripton:

/opt/mysql/data2 directory is the first I created by the following commands:

mkdir -p /opt/mysql/data2
sudo chcon -Rt svirt_sandbox_file_t /opt/mysql/data2

docker run --name confluence-mysql  -d \
  -p 3307:3306 \
  -e 'DB_USER=ezview' -e 'DB_PASS=ezview' -e 'DB_NAME=confluence,jira' \
  -v /opt/mysql/data2:/var/lib/mysql sameersbn/mysql:latest

And then create good container, after running for a period of time, confluence was also produced a lot of data. Server restart after a few days ago, I found that direct execution command:

docker start confluence-mysql 

command, so the error: Could not connect to mysql server. Aborting...

Then I try to generate a new container, which is the command:

mkdir -p /opt/mysql/data2
sudo chcon -Rt svirt_sandbox_file_t /opt/mysql/data2

docker run --name confluence-mysql2  -d \
  -p 3307:3306 \
  -e 'DB_USER=ezview' -e 'DB_PASS=ezview' -e 'DB_NAME=confluence,jira' \
  -v /opt/mysql/data2:/var/lib/mysql sameersbn/mysql:latest

Also report the error: Could not connect to mysql server. Aborting...

fye commented 9 years ago

The attach is my docker container list: 360 16490203678693

sameersbn commented 9 years ago

@fye can you pull down the updated latest tag from the docker and retry

docker pull sameersbn/mysql:latest

There was one particular use case that was fixed recently. Can you test with the updated image.

sameersbn commented 9 years ago

@fye if that does not help, please test after disabling selinux with setenforce 0 to make sure that selinux is not causing any issue. It probably is not, but just to be sure.

fye commented 9 years ago

@sameersbn , I found my problems. I use the following command, that is ok:

docker run --name confluence-mysql2  -d \
  -p 3307:3306 \
  -v /opt/mysql/data2:/var/lib/mysql sameersbn/mysql:latest
docker stop confluence-mysql2
docker start confluence-mysql2

also works.

sameersbn commented 9 years ago

@fye what was the problem?

fye commented 9 years ago

@sameersbn , I don't know why, I removed the following args:

-e 'DB_USER=ezview' -e 'DB_PASS=ezview' -e 'DB_NAME=confluence,jira'
fye commented 9 years ago

And i followed your method, include disabled selinux with setenforce 0, that's not ok, same error like before. I removed the above args, then worked fine.

sameersbn commented 9 years ago

@fye did you try updating the sameersbn/mysql image?

fye commented 9 years ago

@sameersbn , Yes, I had update the image, also the same error.

sameersbn commented 9 years ago

@fye got it.

netflash commented 8 years ago

Got same error here's my docker-compose file

mysql:
    image: sameersbn/mysql
    environment:
        - DB_USER=db
        - DB_PASS=db
        - DB_NAME=db

root@pass:/opt/teampass# docker-compose up mysql Recreating teampass_mysql_1 Attaching to teampass_mysql_1 mysql_1 | Could not connect to mysql server. Aborting... teampass_mysql_1 exited with code 1

sameersbn commented 8 years ago

@netflash Looks like you have stopped containers which docker-compose is reusing, can you remove the stopped containers before retrying. Also you may want to pull the most recent image from the docker hub.

Here are my test results:

# docker-compose up
Creating mysql_mysql_1
Attaching to mysql_mysql_1
mysql_1 | Installing database...
mysql_1 | Starting MySQL server...
mysql_1 | Waiting for database server to accept connections..
mysql_1 | Creating debian-sys-maint user...
mysql_1 | Creating database "db"...
mysql_1 | Granting access to database "db" for user "db"...
mysql_1 | 151221 16:35:36 mysqld_safe Logging to syslog.
mysql_1 | 151221 16:35:36 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
^CGracefully stopping... (press Ctrl+C again to force)
Stopping mysql_mysql_1 ... done

ERROR: 
Aborting.
# docker-compose up
Starting mysql_mysql_1
Attaching to mysql_mysql_1
mysql_1 | Creating database "db"...
mysql_1 | Granting access to database "db" for user "db"...
mysql_1 | 151221 16:35:45 mysqld_safe Logging to syslog.
mysql_1 | 151221 16:35:45 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
pascalandy commented 7 years ago

Looks we could close ticket.

plori commented 5 years ago

Hi,

I know this is a very old issue.

We had a similar problem, when restarting the mysql-redmine docker container. It boiled down to the modified mysql root user password (we just dont want to have none). As you can see from the following lines, the mysql root user is used to test for a running server. But since we changed the password it can not access the database in line 78...

https://github.com/sameersbn/docker-mysql/blob/b33e19d07627834fb290aa59b4f772bd65d91c28/entrypoint.sh#L71-L88

Possibly there should be a more robust way in checking for database status, but I am not really that experienced to provide a solution.