Can't connect to local MySQL server through socket

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
kysdaddy
Posts: 14
Joined: Sat Jul 11, 2020 10:50 pm

Can't connect to local MySQL server through socket

Post by kysdaddy »

Hello,

I keep having the same issue with the SQL database. I am running DLANDON Unraid docker, I followed DLANDON's trouble shooting steps to start zoneminder container without starting the database or Zoneminder, I sent that forum the results and DLANDON suggested I come here. I am pasting those results below the set of warnings from the log.

I have deleted everything and started over from scratch 3 times and each time after a week or so Zoneminder fails to load and I get these warnings.

Thanks for any suggestions or help!!


DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 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' (111) 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' (111) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
Jul 22 12:47:00 853d22092257 zmupdate[1125]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) error val:]
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.
Jul 22 12:47:00 853d22092257 zmupdate[1125]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) error val:]
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' (111) 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' (111) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
Jul 22 12:47:00 853d22092257 zmupdate[1127]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) error val:]
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 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.
Jul 22 12:47:00 853d22092257 zmupdate[1127]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) error val:]
Starting ZoneMinder:
DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 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' (111) 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' (111) at /usr/share/perl5/ZoneMinder/Database.pm line 110.
Jul 22 12:47:00 853d22092257 zmpkg[1137]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) error val:]
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/share/perl5/ZoneMinder.pm line 33.
BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder.pm line 33.
Compilation failed in require at /usr/bin/zmpkg.pl line 34.
BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 34.
Jul 22 12:47:00 853d22092257 zmpkg[1137]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) error val:]
ZoneMinder failed to start

*** /etc/my_init.d/40_firstrun.sh failed with status 255

*** Killing all processes...
Jul 22 12:47:00 853d22092257 syslog-ng[20]: syslog-ng shutting down; version='3.25.1'



I have no problem removing everything and starting over but something that I am doing must be wrong to get the same issue every time.

Please help.

Chas

(DLANDON trouble shooting)
I am really sorry. I was able to follow the instructions and received this when I tried to start ZM

root@Tower:~# docker exec -it Zoneminder /bin/bash
root@ef02f6c53378:/# service mysql start
* Starting MariaDB database server mysqld [fail]
root@ef02f6c53378:/# service zoneminder start
Starting ZoneMinder:
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.
07/22/21 13:18:22.026917 zmpkg[1176].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:]
07/22/21 13:18:22.027215 zmpkg[1176].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.
07/22/21 13:18:22.027685 zmpkg[1176].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:]
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/share/perl5/ZoneMinder.pm line 33.
BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder.pm line 33.
Compilation failed in require at /usr/bin/zmpkg.pl line 34.
BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 34.
ZoneMinder failed to start

Thank you in advance
Chas
User avatar
burger
Posts: 390
Joined: Mon May 11, 2020 4:32 pm

Re: Can't connect to local MySQL server through socket

Post by burger »

Docker is more difficult to troubleshoot. Perhaps you would be better off using a bare metal ZM install.

Mysql is (I'm assuming) crashing. There are occasionally memory leaks in ZM for various reasons (in 1.34). I resolve this with a weekly or monthly reboot. Otherwise, if you wanted to troubleshoot this, one option would be to setup some CPU / Process monitoring in the host (Cacti, Zabbix) another option would be to follow any of the system logs to see if there's some reason things are crashing. My guess is, that you need more power/resources in the machine, or you are running out of memory. You could also try lowering FPS/Resolution of the cameras and see if that stabilizes the container.
fastest way to test streams:
ffmpeg -i rtsp://<user>:<pass>@<ipaddress>:554/path ./output.mp4 (if terminal only)
ffplay rtsp://<user>:<pass>@<ipaddress>:554/path (gui)
find paths on ispydb or in zm hcl

If you are new to security software, read:
https://wiki.zoneminder.com/Dummies_Guide
SteveGilvarry
Posts: 494
Joined: Sun Jun 29, 2014 1:12 pm
Location: Melbourne, AU

Re: Can't connect to local MySQL server through socket

Post by SteveGilvarry »

Funny I saw you get punted over here from Unraid and I was thinking looks like a problem with Docker. Given it is supposed to just work out of the box. But some issue using the DB so let's check it exists.

Anyway try at CLI in Docket Container as per previous docker exec command you used.
Then

Code: Select all

mysql -u zmuser -p
and zmpass when asked for password. I am not sure you will get past this, but if you do then you know credentials are OK.

See if Db called ZM db exists.

Code: Select all

show databases;
Switch to it

Code: Select all

use zm;

Code: Select all

show tables;
Looks like the SQL DB is persisted in the config folder so perhaps you had a failed install and now the DB is stuffed and keeps reloading every time you install. Only guessing as I don't use Unraid and Docker, but willing to have a look at it.
Production Zoneminder 1.37.x (Living dangerously)
Random Selection of Cameras (Dahua and Hikvision)
kysdaddy
Posts: 14
Joined: Sat Jul 11, 2020 10:50 pm

Re: Can't connect to local MySQL server through socket

Post by kysdaddy »

Sorry about the long delay.
I keep having the issue, sometimes an app data restore will fix it for a couple of weeks sometimes rebuilding everything is the only way to get it back

The database crashed again

What do I do if I can't get past the password?
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Chas
kysdaddy
Posts: 14
Joined: Sat Jul 11, 2020 10:50 pm

Re: Can't connect to local MySQL server through socket

Post by kysdaddy »

Update;
I deleted everything and rebuilt it again.
This time I checked for answers to your questions/suggestions.

I was able to log in using zmpass
the response to "show databases;" was
+--------------------+
| Database |
+--------------------+
| information_schema |
| zm |
+--------------------+
2 rows in set (0.009 sec)

MariaDB [(none)]> use zm;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zm]> show tables;
+-----------------+
| Tables_in_zm |
+-----------------+
| Config |
| ControlPresets |
| Controls |
| Devices |
| Event_Summaries |
| Events |
| Events_Archived |
| Events_Day |
| Events_Hour |
| Events_Month |
| Events_Week |
| Filters |
| Frames |
| Groups |
| Groups_Monitors |
| Logs |
| Manufacturers |
| Maps |
| Models |
| MonitorPresets |
| Monitor_Status |
| Monitors |
| MontageLayouts |
| Servers |
| Sessions |
| Snapshot_Events |
| Snapshots |
| States |
| Stats |
| Storage |
| TriggersX10 |
| Users |
| ZonePresets |
| Zones |
+-----------------+
34 rows in set (0.003 sec)

I assume that this means it is working correctly, yes?

The real question is this, what do I do the next time it fails, I couldn't get past the zmpass login when it failed.

Chas
User avatar
bkjaya1952
Posts: 282
Joined: Sat Aug 25, 2018 3:24 pm
Location: Sri Lanka

Re: Can't connect to local MySQL server through socket

Post by bkjaya1952 »

Please try the up to date simple docker repository used in the following link

https://hub.docker.com/r/bkjaya1952/doc ... 7.4-mysql8
Post Reply