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

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

Open
fye opened this issue Jun 19, 2015 · 19 comments

Comments

@fye
Copy link

fye commented Jun 19, 2015

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
Copy link
Owner

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

@fye
Copy link
Author

fye commented Jun 23, 2015

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
Copy link
Owner

@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
Copy link
Author

fye commented Jun 23, 2015

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
Copy link
Author

fye commented Jun 23, 2015

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
Copy link
Author

fye commented Jun 23, 2015

The attach is my docker container list:
360 16490203678693

@sameersbn
Copy link
Owner

@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
Copy link
Owner

@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
Copy link
Author

fye commented Jun 24, 2015

@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
Copy link
Owner

@fye what was the problem?

@fye
Copy link
Author

fye commented Jun 24, 2015

@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
Copy link
Author

fye commented Jun 24, 2015

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
Copy link
Owner

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

@fye
Copy link
Author

fye commented Jul 1, 2015

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

@sameersbn
Copy link
Owner

@fye got it.

@netflash
Copy link

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
Copy link
Owner

@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
Copy link

Looks we could close ticket.

@plori
Copy link

plori commented Feb 20, 2019

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

# start mysql server
echo "Starting MySQL server..."
/usr/bin/mysqld_safe >/dev/null 2>&1 &
# wait for mysql server to start (max 30 seconds)
timeout=30
echo -n "Waiting for database server to accept connections"
while ! /usr/bin/mysqladmin -u root status >/dev/null 2>&1
do
timeout=$(($timeout - 1))
if [ $timeout -eq 0 ]; then
echo -e "\nCould not connect to database server. Aborting..."
exit 1
fi
echo -n "."
sleep 1
done
echo

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants