I think the core of the MariaDB error is probably this part:
The error messages that follow this look like a “cascade” where each subroutine fails because the one before it did.
This is also helpful:
This command starts an interactive database client, for it to work the server must already be running. I now have a theory!
There is already another systemd service file that is starting MariaDB at boot, but it is not called mysql.service. (Probably created automatically when the mariadb package was installed, since that is what most people will want it to do.)
A systemd service file called mysql.service does exist or is an allowed alias, but is not enabled by default
Adding a dependency on mysql.service tells systemd to try to start it, but the first service has already started MariaDB, so this fails because two instances of MariaDB cannot be managing the same files.
I think this is possible because of the strange MySQL/MariaDB naming situation, and also MariaDB supports “templated unit files” that look like mariadb@node1.service, where the part after the @ sign is a parameter that is injected into the service file.
Check if sudo systemctl status mariadb.service shows a running service. If it does, change the Requires and Depends in your Python script service to that service name instead.
If not, try sudo systemctl list-units --type=service --state=running, and look for service names that include MySQL or MariaDB. If there is one running you can check the status of that one, whether it’s enabled to start at boot, and so on. And can change the Requires and After options like in #1.
I think it is not clear to anyone when they first try it, so I am happy to try to make it easier for others!
And it feels like instead of things getting simpler over time, every new generation of programmers adds another layer of complex things for us all to learn.
I have tried your suggestion and I give you the result :
mariadb.service - MariaDB 10.5.23 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2024-06-01 19:08:14 CEST; 1h 12min ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 442 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 459 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 477 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environmen>
Process: 698 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 700 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Main PID: 579 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 8 (limit: 1595)
CPU: 4.039s
CGroup: /system.slice/mariadb.service
└─579 /usr/sbin/mariadbd
juin 01 19:08:13 Raspi2 mariadbd[579]: 2024-06-01 19:08:13 0 [Note] InnoDB: Buffer pool(s) load completed at 240601 19:08:13
juin 01 19:08:13 Raspi2 mariadbd[579]: 2024-06-01 19:08:13 0 [Note] Reading of all Master_info entries succeeded
juin 01 19:08:13 Raspi2 mariadbd[579]: 2024-06-01 19:08:13 0 [Note] Added new Master_info '' to hash table
juin 01 19:08:13 Raspi2 mariadbd[579]: 2024-06-01 19:08:13 0 [Note] /usr/sbin/mariadbd: ready for connections.
juin 01 19:08:13 Raspi2 mariadbd[579]: Version: '10.5.23-MariaDB-0+deb11u1' socket: '/run/mysqld/mysqld.sock' port: 3306 Raspbian 11
juin 01 19:08:14 Raspi2 systemd[1]: Started MariaDB 10.5.23 database server.
juin 01 19:08:14 Raspi2 /etc/mysql/debian-start[702]: Upgrading MySQL tables if necessary.
juin 01 19:08:14 Raspi2 mariadbd[579]: 2024-06-01 19:08:14 3 [Warning] Access denied for user 'root'@'localhost' (using password: NO)
juin 01 19:08:14 Raspi2 mariadbd[579]: 2024-06-01 19:08:14 4 [Warning] Access denied for user 'root'@'localhost' (using password: NO)
juin 01 19:08:14 Raspi2 debian-start[716]: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
It seems that there is only an issue with the password but I have an idea for that and I will test it tomorrow afternoon.
I have tried the command : sudo systemctl list-units --type=service --state=running and mariadb is running.
I have tried the same without --state=running and I see mysql has failed.
I will continue tomrrow afternoon as I have to stop now.
I am trying an other way via anacron as cron is not working too.
This is good! So I think you can mostly ignore “mysql.service”, and use “mariadb.service” for Requires / After in your Python service, and that should correctly tell systemd to wait to start your Python script until after MariaDB is ready.
The password issue I am not sure about, so I am glad you have an idea to try.
It is good ! I have used the mariadb in requires and after and the script is launched and works. I still have the password warnings for some connections as root with no password, but I don’t know where theis connections are asked. For me, my only connections are with password and they are good as I find the datas in the base.
I think this is not so important, only if you want to understand the issue up to the end, but for me, it works and I am happy with it.
Many thanks for your help. I would never have succeeded by myself.