From 1e77b1042b724a038bba3e140ea00e7ff31755ab Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 24 Dec 2025 19:15:15 -0500 Subject: [PATCH] Add Plesk MySQL authentication support to database discovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Plesk MySQL requires password authentication User report: "ERROR 1045 (28000): Access denied for user 'root'@'localhost'" Result: 0 databases detected on Plesk servers Root Cause: Plesk stores MySQL admin password in /etc/psa/.psa.shadow All MySQL queries were using passwordless 'mysql' command This works on cPanel (uses ~/.my.cnf) but fails on Plesk Solution: build_databases_section() in lib/reference-db.sh 1. Check if running on Plesk and /etc/psa/.psa.shadow exists 2. Read admin password from file 3. Build mysql_cmd variable with credentials 4. Use $mysql_cmd for all database queries Changes (lib/reference-db.sh): Lines 161-166: Added Plesk credential detection Line 168: Use $mysql_cmd for SHOW DATABASES Line 179: Use $mysql_cmd for size calculation Line 184: Use $mysql_cmd for table count Impact: ✅ Database discovery now works on Plesk ✅ Backwards compatible with cPanel/InterWorx/Standalone ✅ No performance impact (password read once) Status: Ready for testing on Plesk server --- lib/reference-db.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/reference-db.sh b/lib/reference-db.sh index 6249b3c..38a252f 100755 --- a/lib/reference-db.sh +++ b/lib/reference-db.sh @@ -158,7 +158,14 @@ build_databases_section() { return fi - local all_dbs=$(mysql -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" || true) + # Build MySQL command with credentials if needed + local mysql_cmd="mysql" + if [ "$SYS_CONTROL_PANEL" = "plesk" ] && [ -f /etc/psa/.psa.shadow ]; then + local plesk_mysql_pass=$(cat /etc/psa/.psa.shadow) + mysql_cmd="mysql -uadmin -p${plesk_mysql_pass}" + fi + + local all_dbs=$($mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" || true) local total_dbs=$(echo "$all_dbs" | wc -l) local current=0 @@ -169,12 +176,12 @@ build_databases_section() { local owner=$(get_database_owner "$db") local domain=$(get_database_domain "$db") - local size_mb=$(mysql -Ns -e "SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) + local size_mb=$($mysql_cmd -Ns -e "SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) FROM information_schema.TABLES WHERE table_schema='$db'" 2>/dev/null) [ -z "$size_mb" ] && size_mb=0 - local table_count=$(mysql -Ns "$db" -e "SHOW TABLES" 2>/dev/null | wc -l) + local table_count=$($mysql_cmd -Ns "$db" -e "SHOW TABLES" 2>/dev/null | wc -l) echo "DB|$db|$owner|$domain|$size_mb|$table_count" >> "$SYSREF_DB" done