Installation Error during Update Emoncms database

Been trying for a couple of days to install emoncms on Debian 12 but it keeps getting an Uncaught mysqli_sql_exception while trying to update the db. Everything else appears to go fine during the installation.

PHP Fatal error:  Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11

I can login to the emoncms database with the config.ini supplied user and password and can see that it hasn’t been populated. This installation is running PHP8.2 and mariadb 10.11.6. Any ideas what might be going on?
Here’s the whole log.

Script output also stored in /home/hominoid/main.sh.log
Started: Thu May 16 01:53:13 PM EDT 2024

-------------------------------------------------------------
EmonSD Install
-------------------------------------------------------------
Warning: The default configuration of this script applies
significant modification to the underlying system!

Would you like to review the build script config before starting? (y/n) apt-get update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Get:2 http://security.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Hit:3 http://deb.debian.org/debian bookworm-updates InRelease
Hit:4 https://download.docker.com/linux/debian bookworm InRelease
Hit:5 http://ppa.linuxfactory.or.kr bookworm InRelease
Fetched 48.0 kB in 3s (14.7 kB/s)
Reading package lists...
-------------------------------------------------------------
apt-get upgrade
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
-------------------------------------------------------------
apt-get dist-upgrade
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
-------------------------------------------------------------
apt-get clean

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Important: Did you get a request to reboot your machine, if so we recommend you do this now.
Would you like to exit installation to reboot your machine? (y/n) -------------------------------------------------------------
Reading package lists...
Building dependency tree...
Reading state information...
git is already the newest version (1:2.39.2-1.1).
build-essential is already the newest version (12.9).
python3-pip is already the newest version (23.0.1+dfsg-1).
python3-dev is already the newest version (3.11.2-1+b1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
-------------------------------------------------------------
-------------------------------------------------------------
Apache configuration
-------------------------------------------------------------
Reading package lists...
Building dependency tree...
Reading state information...
apache2 is already the newest version (2.4.59-1~deb12u1).
gettext is already the newest version (0.21-12).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
-- emoncms www folder already installed
-- log folder already exists
Module rewrite already enabled
Conf emonsd already enabled
Site 000-default already disabled
Site emoncms already enabled
-------------------------------------------------------------
Setup the Mariadb server (MYSQL)
-------------------------------------------------------------
Reading package lists...
Building dependency tree...
Reading state information...
mariadb-server is already the newest version (1:10.11.6-0+deb12u1).
mariadb-client is already the newest version (1:10.11.6-0+deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
-- Secure MYSQL
-- Create emoncms database
ERROR 1007 (HY000) at line 1: Can't create database 'emoncms'; database exists
-- Add user:emoncms and assign to database:emoncms
ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'emoncms'@'localhost'
-------------------------------------------------------------
Install PHP
-------------------------------------------------------------
-- not ARMv6 architecture OK to use PHP8.1
Reading package lists...
Building dependency tree...
Reading state information...
php8.2 is already the newest version (8.2.18-1~deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
php8.2-mysql is already the newest version (8.2.18-1~deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
php8.2-gd is already the newest version (8.2.18-1~deb12u1).
php8.2-curl is already the newest version (8.2.18-1~deb12u1).
php-pear is already the newest version (1:1.10.13+submodules+notgz+2022032202-2).
php8.2-dev is already the newest version (8.2.18-1~deb12u1).
php8.2-common is already the newest version (8.2.18-1~deb12u1).
php8.2-mbstring is already the newest version (8.2.18-1~deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date
-------------------------------------------------------------
Redis configuration
-------------------------------------------------------------
Reading package lists...
Building dependency tree...
Reading state information...
redis-server is already the newest version (5:7.0.15-1~deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
-------------------------------------------------------------

fatal: destination path 'phpredis' already exists and is not an empty directory.
Configuring for:
PHP Api Version:         20220829
Zend Module Api No:      20220829
Zend Extension Api No:   420220829
configure.ac:165: warning: The macro `AC_PROG_LIBTOOL' is obsolete.
configure.ac:165: You should run autoupdate.
build/libtool.m4:100: AC_PROG_LIBTOOL is expanded from...
configure.ac:165: the top level
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -Wl,-rpath,... yes
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking target system type... aarch64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20220829 -I/usr/include/php/20220829/main -I/usr/include/php/20220829/TSRM -I/usr/include/php/20220829/Zend -I/usr/include/php/20220829/ext -I/usr/include/php/20220829/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20220829
checking for PHP installed headers prefix... /usr/include/php/20220829
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... gawk
checking whether to enable redis support... yes, shared
checking whether to enable sessions... yes
checking whether to enable json serializer support... yes
checking whether to enable igbinary serializer support... no
checking whether to enable msgpack serializer support... no
checking whether to enable lzf compression... no
checking use system liblzf... no
checking whether to enable Zstd compression... no
checking use system libzstd... yes
checking whether to enable lz4 compression... no
checking use system liblz4... no
checking for hash includes... /usr/include/php/20220829
checking for json includes... /usr/include/php/20220829
checking for redis json support... enabled
checking for redis igbinary support... disabled
checking for pkg-config... /usr/bin/pkg-config
checking for git... yes
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert aarch64-unknown-linux-gnu file names to aarch64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert aarch64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
/bin/bash /opt/openenergymonitor/EmonScripts/install/phpredis/libtool --tag=CC --mode=install cp ./redis.la /opt/openenergymonitor/EmonScripts/install/phpredis/modules
libtool: install: cp ./.libs/redis.so /opt/openenergymonitor/EmonScripts/install/phpredis/modules/redis.so
libtool: install: cp ./.libs/redis.lai /opt/openenergymonitor/EmonScripts/install/phpredis/modules/redis.la
libtool: finish: PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin" ldconfig -n /opt/openenergymonitor/EmonScripts/install/phpredis/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /opt/openenergymonitor/EmonScripts/install/phpredis/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib/php/20220829/
-------------------------------------------------------------
extension=redis.soRequirement already satisfied: redis in /usr/local/lib/python3.11/dist-packages (5.0.4)
Requirement already satisfied: async-timeout>=4.0.3 in /usr/local/lib/python3.11/dist-packages (from redis) (4.0.3)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
-------------------------------------------------------------
Mosquitto Server installation and configuration
-------------------------------------------------------------
Reading package lists...
Building dependency tree...
Reading state information...
mosquitto is already the newest version (2.0.11-1.2+deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
libmosquitto-dev is already the newest version (2.0.11-1.2+deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
-------------------------------------------------------------
Mosquitto Client installation and configuration
-------------------------------------------------------------
Reading package lists...
Building dependency tree...
Reading state information...
libmosquitto-dev is already the newest version (2.0.11-1.2+deb12u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

fatal: destination path 'Mosquitto-PHP' already exists and is not an empty directory.
Configuring for:
PHP Api Version:         20220829
Zend Module Api No:      20220829
Zend Extension Api No:   420220829
configure.ac:165: warning: The macro `AC_PROG_LIBTOOL' is obsolete.
configure.ac:165: You should run autoupdate.
build/libtool.m4:100: AC_PROG_LIBTOOL is expanded from...
configure.ac:165: the top level
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -Wl,-rpath,... yes
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking target system type... aarch64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20220829 -I/usr/include/php/20220829/main -I/usr/include/php/20220829/TSRM -I/usr/include/php/20220829/Zend -I/usr/include/php/20220829/ext -I/usr/include/php/20220829/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20220829
checking for PHP installed headers prefix... /usr/include/php/20220829
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... gawk
checking for mosquitto support... yes, shared
checking for mosquitto files in default path... checking /usr... found in /usr
checking for cc options needed to detect all undeclared functions... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking whether strerror_r is declared... yes
checking whether strerror_r returns char *... no
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert aarch64-unknown-linux-gnu file names to aarch64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert aarch64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
/bin/bash /opt/openenergymonitor/EmonScripts/install/Mosquitto-PHP/libtool --tag=CC --mode=install cp ./mosquitto.la /opt/openenergymonitor/EmonScripts/install/Mosquitto-PHP/modules
libtool: install: cp ./.libs/mosquitto.so /opt/openenergymonitor/EmonScripts/install/Mosquitto-PHP/modules/mosquitto.so
libtool: install: cp ./.libs/mosquitto.lai /opt/openenergymonitor/EmonScripts/install/Mosquitto-PHP/modules/mosquitto.la
libtool: finish: PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin" ldconfig -n /opt/openenergymonitor/EmonScripts/install/Mosquitto-PHP/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /opt/openenergymonitor/EmonScripts/install/Mosquitto-PHP/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib/php/20220829/
-------------------------------------------------------------
extension=mosquitto.so-------------------------------------------------------------
Install Emoncms Core
-------------------------------------------------------------
-- emoncms already installed
-- log folder already exists
-- log file already exists
-- emoncms settings.ini already exists
-- datadir phpfina already exists
-- datadir phpfiwa already exists
-- datadir phptimeseries already exists
-------------------------------------------------------------
Install Emoncms Services
-------------------------------------------------------------
-- installing feedwriter to /var/www/emoncms/scripts/services/feedwriter/feedwriter.service
feedwriter.service already installed
-- installing service-runner to /var/www/emoncms/scripts/services/service-runner/service-runner.service
service-runner.service already installed
-- installing service-runner drop-in User=hominoid
-- installing feedwriter drop-in User=hominoid
-- installing service-runner to /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.service
emoncms_mqtt.service already installed
-- installing emoncms_mqtt drop-in User=hominoid


-------------------------------------------------------------
Install Emoncms Core Modules
-------------------------------------------------------------
-- Module dashboard already exists
-- Module app already exists
-- Module graph already exists
-- Module device already exists
-- Module backup already exists
-- Module usefulscripts already exists
-- Module network already exists
-- Module sync already exists
-- Module postprocess already exists
-- Update Emoncms database
PHP Fatal error:  Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11

Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11

Script output also stored in /home/hominoid/main.sh.log

Hello @hominoid, early on in the process I see that you have this error, it fails to create the database as it already exists and then fails to add a user to the database - it doesnt give a reason why:

You could try creating that user manually perhaps and explore what answers there are on more general mysql Q&A sites give for why that’s failed?

Please excuse me, I should have been clearer. The log is from a second run which why it says the database exists and it cannot create the user because it also existed from an earlier attempt. Before posting my question I did verify the user is setup correctly and valid by logging into mariadb with the user name and password supplied during the emoncms installation. I could also can see the emoncms database was created but not populated, there were no tables. I did another fresh OS load and emoncms installation earlier today and everything was error free until it tries to populate the database as reported in the OP. It still throws this error:

PHP Fatal error:  Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11

To verify I was doing things correctly I did yet another fresh install on Ubuntu 20.4 and was able to successfully install emoncms using the same config.ini that I was using on Debian 12. As background, I was on Ubuntu 20.4 previously but wanted to move to a newer OS version and Debian. Over the last few days I have done about 8-12 Debian installations pursuing different ideas with no success, and each time the script fails at the same place as noted above. In summery, the mariadb user and database is created correctly and is accessible from a shell, it appears that the script is not able to access it. Any ideas?

After the successful Ubuntu 20.4 installation I did another fresh Debian 12 installation from deb.debian.org and the emoncms install failed in the same way. As I had indicated previously there are no errors or problems that I can see initially. It creates the user and the database and continues until it tries to populate the it and then errors. FYI, this is an Odroid-M1 SBC with 8GiB memory running kernel 6.1 from a NVME.

This is a partial of the main.sh.log. It’s to long to post and I don’t have upload privileges.

Script output also stored in /home/hominoid/main.sh.log
Started: Fri May 17 09:24:31 PM EDT 2024
.
.
.

Selecting previously unselected package mysql-common.
Preparing to unpack .../01-mysql-common_5.8+1.1.0_all.deb ...
.
.
.
Setting up mariadb-plugin-provider-bzip2 (1:10.11.6-0+deb12u1) ...
Setting up mariadb-plugin-provider-lzma (1:10.11.6-0+deb12u1) ...
Setting up mariadb-plugin-provider-lzo (1:10.11.6-0+deb12u1) ...
Setting up mariadb-plugin-provider-lz4 (1:10.11.6-0+deb12u1) ...
Setting up mariadb-plugin-provider-snappy (1:10.11.6-0+deb12u1) ...
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u7) ...
Processing triggers for mariadb-server (1:10.11.6-0+deb12u1) ...
-- Secure MYSQL
-- Create emoncms database
-- Add user:emoncms and assign to database:emoncms
-------------------------------------------------------------
Install PHP
-------------------------------------------------------------
-- not ARMv6 architecture OK to use PHP8.1
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libapache2-mod-php8.2 php-common php8.2-cli php8.2-common php8.2-opcache
  php8.2-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php8.2 php-common php8.2 php8.2-cli php8.2-common
  php8.2-opcache php8.2-readline
.
.
.
-------------------------------------------------------------
Install Emoncms Core Modules
-------------------------------------------------------------
-- Installing module: dashboard
Cloning into 'dashboard'...
-- Installing module: app
Cloning into 'app'...
-- Installing module: graph
Cloning into 'graph'...
-- Installing module: device
Cloning into 'device'...
-- Installing module: backup
Cloning into 'backup'...
--- UI directory symlink
- Copying default.config.cfg to config.cfg
- Setting config.cfg settings
- creating /etc/php/8.2/mods-available/emoncmsbackup.ini
post_max_size = 3G
upload_max_filesize = 3G
upload_tmp_dir = /var/opt/emoncms/backup/uploads
- phpenmod emoncmsbackup
- creating /var/opt/emoncms/backup directory
- creating /var/opt/emoncms/backup/uploads directory
- restarting apache

-- Installing module: usefulscripts
Cloning into 'usefulscripts'...
-- Installing module: network
Cloning into 'network'...
--- UI directory symlink
This script must be run as root
Try "sudo /opt/emoncms/modules/network/install.sh"

-- Installing module: sync
Cloning into 'sync'...
--- UI directory symlink
-- Installing module: postprocess
Cloning into 'postprocess'...
--- UI directory symlink
-- Update Emoncms database
PHP Fatal error:  Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11

Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11

Script output also stored in /home/hominoid/main.sh.log

This is the config.ini file

# Edit this config file to suit your local environment if it is not a 
# vanilla Raspberry Pi.
#
# Main settings to look atif a non pi environment
# user - Change user to reflect your OS user
# emonSD_pi_env - Set emonSD_pi_env=0 if not a raspberrypi
# install_redis - REDIS is required for feedwriter, service-runner and emoncms_mqtt services
# locations - modify the install and data storage locations
 
user=hominoid
hostname=odroid-m1
emonSD_pi_env=0

# Components enabled
apt_get_upgrade_and_clean=true
install_apache=true
install_mysql=true
install_php=true
install_redis=true
# To use mqtt but a different server, just set install_mosquitto_server=false
# manually configure mqtt server settings in settings.ini
install_mosquitto=true
install_mosquitto_server=true
install_mosquitto_client=true

install_emoncms_core=true
install_emoncms_modules=true

# RaspberryPi emonSD applicable items - ignored if setting emonSD_pi_env=0
# set to false if not needed

# EmonHub: comment out line above "emoncms_emonpi_modules[config]=stable" if
# you do not wish to have the emoncms emonhub config module installed
install_emonhub=false

install_emoncms_emonpi_modules=false
install_firmware=false
install_emonpilcd=false
install_emonsd=false
install_docker=false
install_network=false

enable_onewire=true

openenergymonitor_dir=/opt/openenergymonitor
emoncms_dir=/opt/emoncms

emoncms_www=/var/www/emoncms
emoncms_log_location=/var/log/emoncms
emoncms_datadir=/var/opt/emoncms

# usernames and passwords below are for default raspberrypi installation
# these can all be changed to own preference

# MySQL
mysql_user=emoncms
mysql_password=hominoidm1
mysql_database=emoncms

# MQTT - change settings.ini after install if server is not local
mqtt_user=emoncms
mqtt_password=hominoidm1

# Default branches
emoncms_core_branch=stable
emonhub_branch=stable
log2ram_branch=rsync_mods

# Core Modules installed in $emoncms_www/Modules
# Configure branches as applicable
declare -A emoncms_modules
emoncms_modules[graph]=stable
emoncms_modules[dashboard]=stable
emoncms_modules[app]=stable
emoncms_modules[device]=stable

# Specific EmonPi / EmonBase Modules installed in $emoncms_www/Modules
# Configure branches as applicable
declare -A emoncms_emonpi_modules
#emoncms_emonpi_modules[config]=stable
#emoncms_emonpi_modules[setup]=stable

# Modules installed in $emoncms_dir/modules
# Configure branches as applicable
declare -A symlinked_emoncms_modules
# symlinked_emoncms_modules[demandshaper]=stable
symlinked_emoncms_modules[sync]=stable
symlinked_emoncms_modules[backup]=stable
symlinked_emoncms_modules[usefulscripts]=stable
symlinked_emoncms_modules[postprocess]=stable
symlinked_emoncms_modules[network]=master

######################################################
## Only change the repositories if you are a developer.
# git repositories
declare -A git_repo
git_repo[emoncms_core]=https://github.com/emoncms/emoncms.git
# main modules
git_repo[config]=https://github.com/emoncms/config.git
git_repo[graph]=https://github.com/emoncms/graph.git
git_repo[dashboard]=https://github.com/emoncms/dashboard.git
git_repo[app]=https://github.com/emoncms/app.git
git_repo[device]=https://github.com/emoncms/device.git
git_repo[setup]=https://github.com/emoncms/setup.git
# symlinked modules
# git_repo[demandshaper]=https://github.com/emoncms/demandshaper.git
git_repo[sync]=https://github.com/emoncms/sync.git
git_repo[backup]=https://github.com/emoncms/backup.git
git_repo[usefulscripts]=https://github.com/emoncms/usefulscripts.git
git_repo[postprocess]=https://github.com/emoncms/postprocess.git
git_repo[network]=https://github.com/emoncms/network.git
# emonhub 
git_repo[emonhub]=https://github.com/openenergymonitor/emonhub.git
# emonpi/rpi specific tools
git_repo[emonpi]=https://github.com/openenergymonitor/emonpi.git
git_repo[log2ram]=https://github.com/openenergymonitor/log2ram.git
git_repo[avrdude-rpi]=https://github.com/openenergymonitor/avrdude-rpi.git
git_repo[RFM2Pi]=https://github.com/openenergymonitor/RFM2Pi
git_repo[emonPiLCD]=https://github.com/openenergymonitor/emonPiLCD

In prior readings the most common causes of the mysqli_sql_exception include:

Incorrect database credentials
Database server connectivity issues
Insufficient permissions for database operations
Invalid SQL syntax
Unexpected data types or formats

So right after the error I tried to login with the same credentials and didn’t have any problems connecting to the emoncms database but of course it had no tables.

hominoid@odroid-m1:~$ mariadb -u emoncms -p emoncms
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 47
Server version: 10.11.6-MariaDB-0+deb12u1 Debian 12

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [emoncms]> SHOW TABLES;
Empty set (0.001 sec)

I could also do this

hominoid@odroid-m1:~$ mariadb -u emoncms -p emoncms -h localhost
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.11.6-MariaDB-0+deb12u1 Debian 12

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [emoncms]> SHOW TABLES;
Empty set (0.001 sec)

and this,

hominoid@odroid-m1:~$ mariadb -u emoncms -p emoncms -h odroid-m1
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 63
Server version: 10.11.6-MariaDB-0+deb12u1 Debian 12

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [emoncms]>

Doing a netstat I see 127.0.0.1:3306

hominoid@odroid-m1:/etc/mysql$ netstat -tulnp 
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:1883          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -                   
tcp6       0      0 ::1:631                 :::*                    LISTEN      -                   
tcp6       0      0 ::1:1883                :::*                    LISTEN      -                   
tcp6       0      0 ::1:6379                :::*                    LISTEN      -                   
udp        0      0 0.0.0.0:631             0.0.0.0:*                           -                   
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -                   
udp        0      0 0.0.0.0:34057           0.0.0.0:*                           -                   
udp6       0      0 :::41180                :::*                                -                   
udp6       0      0 :::5353                 :::*                                -

Based on this information I have to conclude that there are no credential problems and that a connectivity problems is not likely. I’ll continue by looking into what permissions the db user emoncms has and if they are sufficient to do an insert.

Any ideas or suggestions are welcome.

Thanks for the detailed info! Could you try running the database update script manually:

php /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php

Thanks for the suggestion.

hominoid@odroid-m1:~$ php /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php
PHP Fatal error:  Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11

Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php:11
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(11): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 11
hominoid@odroid-m1:~$ 

Could it be that the correct credentials have not been written to /var/www/emoncms/settings.ini?

That appears to be the problem!

hominoid@odroid-m1:/var/www/emoncms$ php /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php
["CREATE TABLE `app_config` (`userid` int(11), `data` text) ENGINE=MYISAM","CREATE TABLE `dashboard` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `userid` int(11), `content` text, `height` int(11) DEFAULT '600', `name` varchar(30) DEFAULT 'no name', `alias` varchar(20) DEFAULT '', `description` varchar(255) DEFAULT 'no description', `main` tinyint(1) DEFAULT '0', `public` tinyint(1) DEFAULT '0', `published` tinyint(1) DEFAULT '0', `showdescription` tinyint(1) DEFAULT '0', `backgroundcolor` varchar(6) DEFAULT 'EDF7FC', `gridsize` tinyint(1) DEFAULT '20', `fullscreen` tinyint(1) DEFAULT '0', `feedmode` varchar(8) DEFAULT 'feedid') ENGINE=MYISAM","CREATE TABLE `device` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `userid` int(11), `nodeid` text, `name` text, `description` text, `type` varchar(32), `devicekey` varchar(64), `time` int(10)) ENGINE=MYISAM","CREATE TABLE `feeds` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `name` text, `userid` int(11), `tag` text, `time` int(10), `value` double, `datatype` int(11) NOT NULL, `public` tinyint(1) DEFAULT '0', `size` int(11), `engine` int(11) DEFAULT '0' NOT NULL, `server` int(11) DEFAULT '0' NOT NULL, `processList` text, `unit` varchar(10) DEFAULT '') ENGINE=MYISAM","CREATE TABLE `graph` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `userid` int(11), `groupid` int(11) DEFAULT '0', `data` text) ENGINE=MYISAM","CREATE TABLE `input` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `userid` int(11), `nodeid` text, `name` text, `description` text, `processList` text, `time` int(10), `value` float) ENGINE=MYISAM","CREATE TABLE `postprocess` (`processid` int(11) NOT NULL auto_increment PRIMARY KEY, `userid` int(11), `status` varchar(255), `status_updated` int(11), `status_message` varchar(255), `params` text) ENGINE=MYISAM","CREATE TABLE `schedule` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `userid` int(11), `name` varchar(30), `expression` text, `timezone` varchar(64) DEFAULT 'UTC', `public` tinyint(1) DEFAULT '0') ENGINE=MYISAM","CREATE TABLE `sync` (`userid` int(11), `host` varchar(64), `username` varchar(30), `apikey_read` varchar(64), `apikey_write` varchar(64)) ENGINE=MYISAM","CREATE TABLE `users` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `username` varchar(30), `email` varchar(64), `password` varchar(64), `salt` varchar(32), `apikey_write` varchar(64), `apikey_read` varchar(64), `lastlogin` datetime, `admin` int(11) NOT NULL, `gravatar` varchar(30) DEFAULT '', `name` varchar(30) DEFAULT '', `location` varchar(30) DEFAULT '', `timezone` varchar(64) DEFAULT 'UTC', `language` varchar(5) DEFAULT 'en_EN', `bio` text, `tags` text, `startingpage` varchar(64) DEFAULT 'feed\/list', `email_verified` int(11) DEFAULT '0', `verification_key` varchar(64) DEFAULT '') ENGINE=MYISAM","CREATE TABLE `rememberme` (`userid` int(11), `token` varchar(40), `persistentToken` varchar(40), `expire` datetime) ENGINE=MYISAM","CREATE TABLE `multigraph` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, `name` text, `userid` int(11), `feedlist` text) ENGINE=MYISAM"]

I wonder why there was a difference between Ubuntu and Debian? For reference here are the current permissions for that folder.

hominoid@odroid-m1:/var/www/emoncms$ ls -al
total 388
drwxr-xr-x 10 hominoid hominoid   4096 May 18 15:54 .
drwxr-xr-x  4 hominoid root       4096 May 17 21:29 ..
-rw-r--r--  1 hominoid hominoid    922 May 17 21:35 composer.json
-rw-r--r--  1 hominoid hominoid   1025 May 17 21:35 COPYRIGHT.txt
-rw-r--r--  1 hominoid hominoid  10214 May 17 21:35 core.php
-rw-r--r--  1 hominoid hominoid   6714 May 17 21:35 default.emonpi.settings.php
-rw-r--r--  1 hominoid hominoid   6834 May 17 21:35 default-settings.ini
-rw-r--r--  1 hominoid hominoid   7296 May 17 21:35 default-settings.php
drwxr-xr-x  5 hominoid hominoid   4096 May 17 21:35 docs
-rw-r--r--  1 hominoid hominoid 165244 May 17 21:35 emoncms_graphic.png
-rw-r--r--  1 hominoid hominoid   2239 May 17 21:35 example.settings.ini
-rw-r--r--  1 hominoid hominoid   2570 May 17 21:35 example.settings.php
drwxr-xr-x  8 hominoid hominoid   4096 May 17 21:35 .git
drwxr-xr-x  3 hominoid hominoid   4096 May 17 21:35 .github
-rw-r--r--  1 hominoid hominoid    355 May 17 21:35 .gitignore
-rw-r--r--  1 hominoid hominoid   8968 May 17 21:35 .htaccess
-rw-r--r--  1 hominoid hominoid  15588 May 17 21:35 index.php
-rw-r--r--  1 hominoid hominoid    223 May 17 21:35 .jshintrc
drwxr-xr-x 12 hominoid hominoid   4096 May 17 21:35 Lib
-rw-r--r--  1 hominoid hominoid  32386 May 17 21:35 LICENSE.txt
-rw-r--r--  1 hominoid hominoid   4615 May 17 21:35 locale.php
drwxr-xr-x 15 hominoid hominoid   4096 May 17 21:35 Modules
-rw-r--r--  1 hominoid hominoid   4934 May 17 21:35 param.php
-rwxr-xr-x  1 hominoid hominoid     92 May 17 21:35 php-info.php
-rw-r--r--  1 hominoid hominoid   4561 May 17 21:35 process_settings.php
-rw-r--r--  1 hominoid hominoid   9622 May 17 21:35 readme.md
-rw-r--r--  1 hominoid hominoid   5096 May 17 21:35 route.php
drwxr-xr-x  7 hominoid hominoid   4096 May 17 21:35 scripts
-rw-r--r--  1 hominoid hominoid    260 May 17 21:35 SECURITY.md
-rw-r--r--  1 hominoid hominoid    320 May 17 21:35 settings.env.ini
-rw-r--r--  1 hominoid hominoid    698 May 18 15:54 settings.ini
drwxr-xr-x  4 hominoid hominoid   4096 May 17 21:35 tests
drwxr-xr-x  3 hominoid hominoid   4096 May 17 21:35 Theme
-rw-r--r--  1 hominoid hominoid    151 May 17 21:35 version.json

Thanks for your help!