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

More comprehensive logs during mysql initialization #385

Closed
wants to merge 1 commit into from

Conversation

aario
Copy link

@aario aario commented Feb 28, 2018

More comprehensive logs during mysql initialization and also visible error messages.
The idea came when I faced a problem with initialization of magento:

mysql                      | 2018-02-28T09:41:21.166088090Z 2018-02-28T09:41:21.166046Z 0 [Note] mysqld: ready for connections.
mysql                      | 2018-02-28T09:41:21.166104229Z Version: '5.7.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
mysql                      | 2018-02-28T09:41:21.921672269Z MySQL init process in progress...
mysql                      | 2018-02-28T09:41:22.932179525Z MySQL init process in progress...
.
.
.
mysql                      | 2018-02-28T09:41:51.203276913Z MySQL init process in progress...
mysql                      | 2018-02-28T09:41:52.206185839Z MySQL init process failed.

There were two solutions on the internet to remove MYSQL_HOST from environment variables and to remove memory limit for docker container both of which was not the case for me. I read through the init script to realize that it tries to send a simple select 1 to the mysql and if it fails it thinks the mysql is still initializing. So continues to retry. When I tried the same select command manually:

echo 'SELECT 1' | mysql --protocol-=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock
mysql: [ERROR] unknown variable 'character_set_client=utf8'

I just realized that it's an error with my config file. So far so good. But:
Isn't it better for the init script to show the actual error message of mysql when it is retrying?
This feature can save hours of frustration for developers. That is why I prepared this pull request.

@@ -99,10 +99,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )

for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
echo 'Trying to connect to mysql...'
if echo 'SELECT 1' | "${mysql[@]}" > /dev/null; then
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stderr can be very useful sometimes. We should not always suppress it. So here I removed the '&'.

@yosifkit
Copy link
Member

yosifkit commented Mar 4, 2020

Apologies for the very long tail 🙇‍♂️

It seems with #471, this was improved:

mysql_note "Waiting for server startup"

mysql_error "Unable to start server."

@yosifkit yosifkit closed this Mar 4, 2020
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

Successfully merging this pull request may close these issues.

2 participants