mythconverg mysql database inside docker

Have a MythTV related problem? Ask for help from other MythTV users here.

Moderator: Forum Moderators

Post Reply
clueo8
Junior
Posts: 21
Joined: Sun Feb 16, 2014 9:02 pm
United States of America

mythconverg mysql database inside docker

Post by clueo8 » Fri May 18, 2018 11:36 am

I'm trying to migrate from a local mysql instance to one inside a docker container which will contain my mythconverg database. I created the mysql instance inside docker, got the user and database migrated and forwarded port 3306 so it's listening on my master backend host; I'm using my own docker network as this mysql container is used for things other than mythtv and I need to continue to use it in this fashion. When I try to start up the backend, it fails as it appears to be trying to make a socket connection to the database rather than TCP:

May 18 07:23:49 Ubuntu-Server mythbackend: mythbackend[8570]: E CoreContext mythdbcon.cpp:243 (OpenDatabase) Driver error was [1/2002]:#012QMYSQL: Unable to connect#012Database error was:#012Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I've tried doing bind mounts (-v) to get the docker container's mysqld.sock file to try and appear on the host system at this expected path, but it never works; the docker container doesn't even start when I use -v /var/run/mysqld:/var/run/mysqld.

I've tried updating my /etc/mythtv/config.xml to use either 127.0.0.1 or my actual local IP address rather then localhost but that doesn't appear to do anything.

Is there anyone running their mythtv database inside of a docker container and have this working with a master backend? Or is there a way to force mythv's master backend to not use a socket connection to the database? (use TCP)

User avatar
bill6502
Developer
Posts: 981
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: mythconverg mysql database inside docker

Post by bill6502 » Fri May 18, 2018 1:12 pm

I don't use Docker, but when MythTV sees localhost or 127.0.0.1 in the
DB setup, it chooses sockets over TCP. Check your setup (or look in
ALL copies of config.xml. If that's the case, you'd choose a Private
Network address, like 192.168.n.n.

clueo8
Junior
Posts: 21
Joined: Sun Feb 16, 2014 9:02 pm
United States of America

Re: mythconverg mysql database inside docker

Post by clueo8 » Fri May 18, 2018 1:52 pm

I did try setting a private network (192.168.x.x) in the config.xml in /etc/mythtv but it didn't work. There is also a mysql.txt file in there that I changed but not sure if that's used. The ~/.mythtv directory is for FE not BE config, correct?

Maybe I should change it via mythtv-setup instead of editing files directly?

User avatar
bill6502
Developer
Posts: 981
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: mythconverg mysql database inside docker

Post by bill6502 » Fri May 18, 2018 2:51 pm

Right, mysql.txt is old. I recall 0.25 and earlier, but I didn't look it up.
I've removed all of mine ages ago. Although it's possible that some
old scripts still use them (in error.)

ls -ld {~,~mythtv}/.mythtv/config.xml . Typically, they are symbolic links
to the file you changed (sorry, I missed that.) Those links have been known
to get broken though. Also, be sure whatever starts the backend (SysV,
Upstart, systemd) isn't setting MYTHCONFDIR to somewhere else.

EDIT: Just look at the line: ... Using configuration directory = ...
in the backend log.

MikeB2013
Senior
Posts: 237
Joined: Mon Jul 25, 2016 4:16 pm
Great Britain

Re: mythconverg mysql database inside docker

Post by MikeB2013 » Fri May 18, 2018 3:36 pm

I think you might need to adjust mysql to force it to listen on tcp.
Assuming a package install of mythtv.

In /etc/mysql/conf.d there is a file named mythtv.cnf which by default has the bind address commented out (# at start of line) by default is looks like this
#bind-address=::

Change the line to have your private network ip address, remove the # at start of line and restart

You also need to make sure that all mythtv config.xml files have the private network ip address, as mentioned by bill6502, and mythtv-setup for the backend also has the private network address set for Primary IP Address / DNS Name in Host Address Backend Setup

Mike

User avatar
pgbennett
Developer
Posts: 225
Joined: Mon Apr 27, 2015 5:41 pm
United States of America

Re: mythconverg mysql database inside docker

Post by pgbennett » Fri May 18, 2018 6:07 pm

Did you check the mysql.conf on the database server? By default it is setup to only listen on 127.0.0.1. You need to comment out the line
bind-address = 127.0.0.1
If using mariadb you need to set it as
bind-address = ::

clueo8
Junior
Posts: 21
Joined: Sun Feb 16, 2014 9:02 pm
United States of America

Re: mythconverg mysql database inside docker

Post by clueo8 » Fri May 18, 2018 7:54 pm

"configuration directory = " in BE log pointed to /home/mythtv/.mythtv which had it's own config.xml which I renamed and symlinked to /etc/mythtv/config.xml.

I then started BE up with a 192 hostname and a non-standard 3307 port for the DB which is fwding to my docker container but it appeared changing the port in the config.xml did not work although I can confirm I see the 192 host in the logs instead of localhost...

Possibly is there another place to change the port? I may just use the standard port but wanted to test this way first...

User avatar
bill6502
Developer
Posts: 981
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: mythconverg mysql database inside docker

Post by bill6502 » Fri May 18, 2018 8:31 pm

If you haven't I'd be sure mysql --host=yourSQLhost --port=3307 --user=mythtv --password mythconverg
works. Otherwise, describing how it "did not work" may help folks watching this
thread. Attaching the BE log is always good.

EDIT: added host

clueo8
Junior
Posts: 21
Joined: Sun Feb 16, 2014 9:02 pm
United States of America

Re: mythconverg mysql database inside docker

Post by clueo8 » Sat May 19, 2018 12:19 am

So I got it to connect finally to my docker container's mysql as long as I forwarded the standard mysql port of 3306 from my host to the container. I tried changing to port 3307 in the config.xml that I know is used because it picked up the server name as soon as I changed that from localhost to my 192.168.x.x, but it would not work, it still uses the 3306 regardless:

When I stopped my local 3306 database from listening and only had my 3307 docker container mysql listening, it wouldn't connect:

Code: Select all

May 18 20:07:24 Ubuntu-Server mythbackend: mythbackend[9105]: I CoreContext mythcontext.cpp:852 (TestDBconnection) Start up testing connections. DB 192.168.x.x, BE , attempt 1, status dbAwake
Also, another snag I ran into was mythweb, which defaults to localhost and it mentions this throughout the code. I started grepping and updating localhost to 192.168.x.x and finally stumbled upon this file that had env variables which I needed to update and restart/reload apache2:

/etc/apache2/sites-enabled$ cat mythweb.conf | grep db
setenv db_server "192.168.x.x" <--- used to be localhost
setenv db_name "mythconverg"
setenv db_login "mythtv"
setenv db_password "********"

This brings up another question; I don't see where you would be able to change the mysql port to something else besides the default 3306 anywhere in mythweb.

User avatar
bill6502
Developer
Posts: 981
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: mythconverg mysql database inside docker

Post by bill6502 » Sun May 20, 2018 6:37 pm

Not clear if you were testing with:
mysql --host=yourContainer --port=3307 --user=mythtv --password mythconverg
as above, but if that fails, it's not a MythTV issue. Maybe /var/log/apache/error.log
would have a hint.

mythweb is on life support, you can write an issue in Trac, but unless
it includes a patch to add db_port, it will be rejected.

There's always <yourBackend>:6544 (for WebFrontend.)

Post Reply