Datadir /home/pi/data/mysql gone after power failure

Hi,
after power failure my EmonPi is missing mysql datadir. I’m using SSD. Emoncms web site is saying:

Can't connect to database, please verify credentials/configuration in settings.ini
Error message: **Connection refused**

I’m not at all sure what should be where, but the datadir appears to be missing.

Some debugging info:

pi@emonpi:~ $ df -hlx tmpfs
 Filesystem      Size  Used Avail Use% Mounted on
 /dev/root       4.0G  3.0G  799M  80% /
 devtmpfs        431M     0  431M   0% /dev
 /dev/mmcblk0p1  253M   54M  199M  22% /boot
 /dev/sda3       106G  544M  100G   1% /var/opt/emoncms
 pi@emonpi:~ $ sudo du -shc /home/pi/data/*
 du: cannot access '/home/pi/data/*': No such file or directory
 0       total
 pi@emonpi:~ $ mysqlcheck --all-databases -r
 mysqlcheck: unknown option '--datadir /home/pi/data/mysql'
 pi@emonpi:~ $ sudo service mysql status
 ● mariadb.service - MariaDB 10.3.23 database server
    Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Mon 2024-05-27 08:03:44 BST; 33s ago
      Docs: man:mysqld(8)
            https://mariadb.com/kb/en/library/systemd/
   Process: 29470 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld code=exited, status=0/SUCCESS)
   Process: 29471 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
   Process: 29473 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit
   Process: 29526 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=2)
  Main PID: 29526 (code=exited, status=2)
    Status: "MariaDB server is down"
 
 May 27 08:03:41 emonpi systemd[1]: Starting MariaDB 10.3.23 database server...
 May 27 08:03:41 emonpi mysqld[29526]: 2024-05-27  8:03:41 0 [Note] /usr/sbin/mysqld (mysqld 10.3.23-MariaDB-0+deb10u1) starting as process 29526 ...
 May 27 08:03:41 emonpi mysqld[29526]: 2024-05-27  8:03:41 0 [Warning] Could not increase number of max_open_files to more than 16364 (request: 32186)
 May 27 08:03:44 emonpi systemd[1]: mariadb.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
 May 27 08:03:44 emonpi systemd[1]: mariadb.service: Failed with result 'exit-code'.
 May 27 08:03:44 emonpi systemd[1]: Failed to start MariaDB 10.3.23 database server.
pi@emonpi:/etc $ sudo fdisk -u -l /dev/sda
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 sectors
Disk model:
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 6CE8EF55-6A8B-4C5F-9B95-93D13EE84657

Device       Start       End   Sectors   Size Type
/dev/sda1     2048    532479    530432   259M EFI System
/dev/sda2   532480   8959999   8427520     4G Linux filesystem
/dev/sda3  8960000 234441614 225481615 107.5G Linux filesystem
pi@emonpi:/etc $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       4.0G  3.0G  787M  80% /
devtmpfs        431M     0  431M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   47M  417M  11% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
tmpfs           1.0M     0  1.0M   0% /var/tmp
tmpfs            30M     0   30M   0% /tmp
tmpfs           1.0M     0  1.0M   0% /var/lib/php/sessions
/dev/mmcblk0p1  253M   54M  199M  22% /boot
/dev/sda3       106G  544M  100G   1% /var/opt/emoncms
log2ram          50M   34M   17M  67% /var/log
tmpfs            93M     0   93M   0% /run/user/1000
pi@emonpi:/etc $ more /etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2

/dev/sda2  /               ext4    defaults,noatime,nodiratime  0  1
/dev/sda3  /var/opt/emoncms   ext2    defaults,noatime,nodiratime  0  2


#PARTUUID=6c586e13-02  /               ext4    defaults,noatime,nodiratime  0  1
#/dev/mmcblk0p3  /var/opt/emoncms   ext2    defaults,noatime,nodiratime  0  2

# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

tmpfs           /tmp                   tmpfs   nodev,nosuid,size=30M,mode=1777 0  0
tmpfs           /var/tmp               tmpfs   nodev,nosuid,size=1M,mode=1777  0  0
tmpfs           /var/lib/php/sessions  tmpfs   nodev,nosuid,size=1M,mode=1777  0  0

All the data seems to be there, e.g., in /var/lib/mysql/emoncms, but has the system just lost some symlinks?

Why is it looking for mysql in that location I wonder?

Is it based on a very old emonSD image?

Checking the mysql install steps it should just be using the standard install locations at least on the newer images /home/pi/data/mysql was probably the older pre EmonScripts data location… EmonScripts/install/mysql.sh at master · openenergymonitor/EmonScripts · GitHub

1 Like

Yes, it is very old emonSD image. What is the current correct location of the mysql files, should say it in /etc/mysql/my.cnf?

EDIT:
Very weird, /etc/mysql/my.cnf had changed to contain

datadir /home/pi/data/mysql

as the last line, in the [client-server] section, commenting that out fixed the issue.