So today I needed a quick script to list all of the mysql databases on the system and compare that to the databases that were created inside of plesk. I wanted to print any databases that were created outside of plesk.
Why you might ask? It came to my attention that some of our system admins were creating databases manually through command line and setting up users that way when doing code deployments onto our shared plesk servers.
Whats wrong with that? Well if the database is outside of plesk, then plesk backup system, and plesk migration manager won’t know about the databases, nor the db users/passwords. This means if you are relying on plesk backup xml, or plesk migration manager for your server upgrades or disaster recovery, you’re going to have an issue with missing databases at some point!
The code is simple and is below. From memory it should work on plesk 8-11 and I have tested it on v10/11 myself.
Next to add to the list, is to set this up as a cron and email our general support queue if a new db is created outside of the plesk system.
To install / run, copy the below into a file called db_checker.php, then at a command line run “php db_checker.php”. You will need to be the root user to run this script.