Linux Setting up MariaDB via Docker
#16
Just use any db tool, connect via the port etc, and import your SQL
Addons I wrote &/or maintain:
OzWeather (Australian BOM weather) | Check Previous Episode | Playback Resumer | Unpause Jumpback | XSqueezeDisplay | (Legacy - XSqueeze & XZen)
Sorry, no help w/out a *full debug log*.
Reply
#17
can i get any tutorial on it ? [Your spam link has been removed and warning given. Benefit of the doubt given for now but we are watching - dangelus]
Reply
#18
I'm not too sure what you want exactly. 

Do you want to let Kodi populate the mariadb in a docker container or do you want to populate the DB yourself with any kind of data?

Let's start with the option to let Kodi connect to the DB and populate it. Please make sure you will read everything first, before starting!!!!

So we will need a container. The easiest way to get a MariaDB Container running is: 

docker run --detach --name maria-test --env MARIADB_USER=kodi --env MARIADB_PASSWORD=my_passwd --env MARIADB_ROOT_PASSWORD=my-root-passwd -p 3306:3306 mariadb

Let's explain this command: 

docker run - will start a container
--name - will give that container a name of your choice
--env MARIADB_USER= - will set up an enviroment-variable for the user for that DB. You can choose the name
--env MARIADB_PASSWORD=my_passwd - will setup an environment-varible for the password for the given user
--env MARIADB_ROOT_PASSWORD= - will setup an environment-variable for the password for the mariadb "root"-user
-p 3306:3306 - will expose the port 3306 from inside the container to the machine the container runs on. So you are able to connect to the container via the IP of that machine and the given port. It's a good pattern to use the same port which runs inside the container. 
mariadb the name of the docker image from docker-hub. Note: This will pull the "latest" image. In case you want to use a specific version, please replace that with: mariadb:10.7

For available tags, please see: https://hub.docker.com/_/mariadb/?tab=tags

Now we have that container running, we still have to configure it. It can also be done by using your own dockerfile, but let's not overcomplicate things.....so let's connect to the running container:

docker exec -it maria-test bash

You will get a shell where you are able to enter some commands. Let's start with: mariadb --help --verbose

You will see a line which looks like: 

Code:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 

So you now know which files are used to configure your MariaDB instance. Please read these docs to understand what we are going to edit any why: https://mariadb.com/kb/en/configuring-ma...aults-file

We are going to edit: /etc/mysql/mariadb.cnf as I doubt you will have more than a single user on that instance. 

As that container is based on Ubuntu and in case you want to edit some of the files, you might need to install an editor:

Code:
apt update
apt install nano

Then edit the specific file: nano /etc/mysql/mariadb.cnf and look for these lines: 

Code:
skip-networking
bind-address = <some ip-address>

These lines might not be in order. So make sure you looked carefully. If you found them, make sure you commenting them out:

Code:
#skip-networking
#bind-address = <some ip-address>

Note: In my tests, those lines (the ones without the "#") haven't existed. So normally you don't need to edit anything. 

Then safe and exit the editor. Exit the container "ctrl + d" and then stop and start the container again: docker stop maria-test && docker start maria-test

To check if the configuration works as expected, connect to the docker again (see above) and execute: mysqld --print-defaults and you shouldn't see any kind of bound IP address. 

After all that is done, please follow our instruction we provide on our wiki to grant permissions to the given user: https://kodi.wiki/view/MySQL/Setting_up_...untu_Linux

You can safely ignore the "sudo service"-command to restart the MariaDB-service as that's done by restarting the container. 

After you have given the user the recommended permissions, please have a read at: https://kodi.wiki/view/MySQL/Setting_up_Kodi to get the advancedsettings.xml file done. Make sure you are using the correct password. The IP in need is the IP of the machine the container runs on. In case it's the same machine, use "127.0.0.1" and "3306" for the port. Make sure Kodi doen't run at the moment you are editing the advancedsettings.xml. In case you are using LibreELEC, make sure to restart LibreELEC after editing the advancedsettings.xml

After this is done, Kodi will use this database and will populate it automatically with the movies which are already in the normal SQL-DB and will add all additional movies to that MariaDB from the next start. 

Be aware, that the database will be gone if you stop and delete that container. To avoid that, you have to use "volumes" for that container which gives the option to mount a path into a container which represents a path on the machine the container runs on. To make the data persistent, please add the following to the "docker run"-command:

-v /my/own/datadir:/var/lib/mysql

The syntax is: /path/on/my/machine:/path/inside/the/container

In case you are using Windows as a docker host it might look like: C:\mysql\:/var/lib/mysql/. Please take this with caution. I'm not a regular windows-user Wink

That's one way of populating the MariaDB. 

In case you are asking to populate a MariaDB which exists in a docker container, you have to use a MySQL/MariaDB client to connect to it. But before that you might need to create a database schema, tables, fields and all that to write data to specific fields in specific tables at specific databases. That might be way more complicated than using Kodi to populate it. Hence my confusion what exactly you are searching for.
Reply
#19
If you are importing from a .sql file its the same as piping any other command.

Code:
docker exec -i "$1" mysql -e "CREATE DATABASE IF NOT EXISTS ${DBNAME};"
zcat $(find "$db"/ -name '*.sql.gz' | sort -n | tail -n 1) \ | docker exec -i "$1" mysql "$DBNAME"

You can work with it from the command line just like anything else. Just have to pipe through the docker daemon. It all works the same though. This is a function from my dump / restore script.

My dump command

Code:
docker exec -t "$2" mysqldump \ --user=backup \ --password=backup \ --single-transaction "$db" \ | gzip > "$FILENAME"

Nothing to complicated about it.
Reply

Logout Mark Read Team Forum Stats Members Help
Setting up MariaDB via Docker0