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

Can't connect to local MySQL server #74

Open
emield12 opened this issue Feb 10, 2021 · 6 comments
Open

Can't connect to local MySQL server #74

emield12 opened this issue Feb 10, 2021 · 6 comments

Comments

@emield12
Copy link

emield12 commented Feb 10, 2021

Hello,
I upgraded my docker image to the latest version today and now the container won't start anymore. The local MySQL database does fails to start.
Docker logs:

 * Starting MySQL database server service   ...done.
 * Warning: Mysql startup timer expired!
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 * First run of mysql in the container, creating ZoneMinder dB.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 * Starting Apache http web server service   ...done.
 * Starting ZoneMinder video surveillance recorder   ...failed!

I am using the ubuntu18.04 version of the image, command:

sudo docker run -d -t -p 1080:80 
-e TZ='Europe/Brussels' 
-v /mnt/user/cctv_rec/Zoneminder/events/:/var/cache/zoneminder/events 
-v /mnt/user/cctv_rec/Zoneminder/images/:/var/cache/zoneminder/images 
-v /mnt/user/appdata/Zoneminder/mysql/:/var/lib/mysql 
-v /mnt/user/appdata/Zoneminder/logs/:/var/log/zm 
--name zoneminder_bis zoneminderhq/zoneminder:latest-ubuntu18.04

Maybe it is related to issue #73, but I am not using an external database.

p.s.: It would be nice to have version tags on the docker images, as now I can't even roll back to a previous version.

@morikplay
Copy link

On Big Sur macOS (11.2.3), i have the same issue.

docker command:

docker run -d -t -p 1080:80 \
--privileged="false" \
    -e TZ="America/Los_Angeles" \
    -v ~/zoneminder/events:/var/cache/zoneminder/events \
    -v ~/zoneminder/images:/var/cache/zoneminder/images \
    -v ~/zoneminder/mysql:/var/lib/mysql \
    -v ~/zoneminder/logs:/var/log/zm \
    --shm-size="512m" \
    --name zoneminder \
    zoneminderhq/zoneminder:latest-ubuntu18.04

Log

* Starting MySQL database server service ...done.

* Warning: Mysql startup timer expired!

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

* First run of mysql in the container, creating ZoneMinder dB.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

* Starting Apache http web server service ...done.

* Starting ZoneMinder video surveillance recorderDBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.

DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.

04/21/21 20:12:31.316398 zmupdate[604].ERR [ZoneMinder::Database:113] [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error val:]

04/21/21 20:12:31.317567 zmupdate[604].ERR [ZoneMinder::Database:113] [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error val:]

DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.

04/21/21 20:12:31.319795 zmupdate[604].ERR [ZoneMinder::Database:113] [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error val:]

Can't call method "prepare_cached" on an undefined value at /usr/share/perl5/ZoneMinder/Config.pm line 96.

BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder/Config.pm line 147.

Compilation failed in require at /usr/bin/zmupdate.pl line 73.

BEGIN failed--compilation aborted at /usr/bin/zmupdate.pl line 73.

DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.

DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.

04/21/21 20:12:31.474320 zmupdate[610].ERR [ZoneMinder::Database:113] [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error val:]

04/21/21 20:12:31.474588 zmupdate[610].ERR [ZoneMinder::Database:113] [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error val:]

DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.

04/21/21 20:12:31.474986 zmupdate[610].ERR [ZoneMinder::Database:113] [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error val:]

Can't call method "prepare_cached" on an undefined value at /usr/share/perl5/ZoneMinder/Config.pm line 96.

BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder/Config.pm line 147.

Compilation failed in require at /usr/bin/zmupdate.pl line 73.

BEGIN failed--compilation aborted at /usr/bin/zmupdate.pl line 73.

...failed!

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 26, 2021
@alexbelgium
Copy link

alexbelgium commented Mar 10, 2022

I have the same issue with same error message when trying to connect to an external database.

Internal database works fine.


 * Remote database credentials detected. Continuing...
 * Looking for remote database server   ...found.
 * Looking for existing remote database   ...found.
 * Starting Apache http web server service   ...done.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
Unable to connect to DB. ZM Cannot continue.
BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder/Config.pm line 150.
Compilation failed in require at /usr/bin/zmupdate.pl line 74.
BEGIN failed--compilation aborted at /usr/bin/zmupdate.pl line 74.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.

@stale stale bot removed the stale label Mar 10, 2022
@EK701
Copy link

EK701 commented Aug 24, 2022

Having the exact same issue using:

docker run -d \
    --name="zoneminder" \
    --restart=unless-stopped \
    -p 10.200.67.20:8080:80/tcp \
    -e TZ="America/Los_Angeles" \
    --shm-size="32G" \
    -v /zm/events:/var/cache/zoneminder/events \
    -v /zm/images:/var/cache/zoneminder/images \
    -v /zm/mysql:/var/lib/mysql \
    -v /zm/logs:/var/log/zm \
    zoneminderhq/zoneminder:latest-ubuntu18.04

Log file:

 * Starting MySQL database server service   ...done.
 * Warning: Mysql startup timer expired!
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 * First run of mysql in the container, creating ZoneMinder dB.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 * Starting Apache http web server service   ...done.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
Unable to connect to DB. ZM Cannot continue.
BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder/Config.pm line 150.
Compilation failed in require at /usr/bin/zmupdate.pl line 74.
BEGIN failed--compilation aborted at /usr/bin/zmupdate.pl line 74.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
Unable to connect to DB. ZM Cannot continue.
BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder/Config.pm line 150.
Compilation failed in require at /usr/bin/zmupdate.pl line 74.
BEGIN failed--compilation aborted at /usr/bin/zmupdate.pl line 74.
 * Starting ZoneMinder video surveillance recorder   ...failed!

Tried removing docker image and pulling it again, but no change.

@habonil23
Copy link

That's a permissions issue. '/var/run/mysql' is owned by mysql and it has 700 permission, so www-data cannot connect to it. Unfortunately, the only way to fix (since the container won't start up, it is creating your own image with dockerfile. I ended up creating my own docker image (using Ubuntu 22.04) and fixed it in the docker file.

@THLIVSQAZ
Copy link

I found use tcp connect and also change the mysql auth plugin can solve this problem
Screen Shot 2022-09-10 at 00 15 14
detail

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

6 participants