[SOLVED] Changing database location

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
whoop
Posts: 22
Joined: Fri Sep 04, 2020 7:08 pm

[SOLVED] Changing database location

Post by whoop »

I am trying to change the default location of the mysql data directory.
I think I did everything correctly and when I run:

Code: Select all

select @@datadir;
in a mysql session I get the new data location.
However when I try to start zoneminder I get the following error for zmpkg.pl in the logs (and zoneminder fails to start):

Code: Select all

ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) error val:]
The /var/lib/mysql/mysql.sock is still the old location and I don't know where zmpkg.pl (or zoneminder) is getting this location from.
Last edited by whoop on Fri Oct 23, 2020 8:49 pm, edited 2 times in total.
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: Changing database location

Post by Magic919 »

One is the data directory, the other (which errors) is the socket for MySQL to connect to. Two different things.
-
whoop
Posts: 22
Joined: Fri Sep 04, 2020 7:08 pm

Re: Changing database location

Post by whoop »

Valid point.

However I was under the impression that moving the entire directory and than editing /etc/my.cnf.d/mariadb-server.cnf:

Code: Select all

[mysqld]
datadir=/new/mysql
socket=/new/mysql/mysql.sock
would also solve the socket problem..

The mysqld service seems to be running fine (select @@datadir; gives me the proper new location).
httpd service seems to be running fine.
Only zoneminder service still fails while pointing at the old socket location --> /var/lib/mysql/mysql.sock in the error.
journalctl -xe:

Code: Select all

-- Unit zoneminder.service has begun starting up.
Oct 23 16:08:21 testserver zmpkg.pl[4130]: DBI connect('database=zm;host=localhost','test',...) failed: Can't connect to local MySQL server through socket >
Oct 23 16:08:21 testserver zmpkg.pl[4130]: DBI connect('database=zm;host=localhost','test',...) failed: Can't connect to local MySQL server through socket >
Oct 23 16:08:21 testserver zmpkg[4130]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' >
Oct 23 16:08:21 testserver zmpkg.pl[4130]: DBI connect('database=zm;host=localhost','test',...) failed: Can't connect to local MySQL server through socket >
Oct 23 16:08:21 testserver zmpkg[4130]: ERR [Error reconnecting to db: errstr:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' >
Oct 23 16:08:21 testserver zmpkg.pl[4130]: Can't call method "prepare_cached" on an undefined value at /usr/share/perl5/vendor_perl/ZoneMinder/Config.pm line>
Oct 23 16:08:21 testserver zmpkg.pl[4130]: BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/ZoneMinder/Config.pm line 147.
Oct 23 16:08:21 testserver zmpkg.pl[4130]: Compilation failed in require at /usr/share/perl5/vendor_perl/ZoneMinder.pm line 33.
Oct 23 16:08:21 testserver zmpkg.pl[4130]: BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/ZoneMinder.pm line 33.
Oct 23 16:08:21 testserver zmpkg.pl[4130]: Compilation failed in require at /usr/bin/zmpkg.pl line 34.
Oct 23 16:08:21 testserver zmpkg.pl[4130]: BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 34.
Oct 23 16:08:21 testserver systemd[1]: zoneminder.service: Control process exited, code=exited status=255
Oct 23 16:08:21 testserver systemd[1]: zoneminder.service: Failed with result 'exit-code'.
Oct 23 16:08:21 testserver systemd[1]: Failed to start ZoneMinder CCTV recording and security system.
-- Subject: Unit zoneminder.service has failed
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: Changing database location

Post by Magic919 »

You could try stating it explicitly in the Zoneminder config file. I’d have thought it would pick it up from my.cnf, just based on Linux experience.
-
whoop
Posts: 22
Joined: Fri Sep 04, 2020 7:08 pm

Re: Changing database location

Post by whoop »

Well it wasn't really straightforward figuring that out(at least not for me). But your suggestion seems to have helped me allot. Thank you.

I added a file named 03-custom.conf to /etc/zm/conf.d/
and added the following:

Code: Select all

ZM_DB_HOST=localhost:/new/mysql/mysql.sock
I think this is the proper way to do it.
Now Zoneminder will start. Have not checked if everything is working though.

Thanks again.
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: [SOLVED] Changing database location

Post by Magic919 »

I’m glad it helped.

Yes, popping that in the custom config file is best practice. It means it doesn’t get clobbered during upgrades later on.
-
Post Reply