A lot of times when we migrate a user from a cPanel based server over to a LEMP stack, it can be very time consuming to create all new databases along with assigning a database user / password to access that database.  This one liner will do all the work for you.

Simply run this in the parent directory of the WordPress installs, it will search for all wp-config.php scripts, pull the database, user and password, create the database, and lastly assign the user / password to the database.

*It does require mysqladmin which most will have available by default.

for wpinstall in $(find "$(pwd)"/ -type f -name wp-config.php | sed 's/wp-config.php//g') 
echo "$wpinstall"

dbname=$(grep DB_NAME "$wpinstall"/wp-config.php | grep -v WP_CACHE_KEY_SALT | cut -d \' -f 4)
echo "Database Name: $dbname"

dbuser=$(grep DB_USER "$wpinstall"/wp-config.php | grep -v WP_CACHE_KEY_SALT | cut -d \' -f 4)
echo "Database User: $dbuser"

dbpass=$(grep DB_PASSWORD "$wpinstall"/wp-config.php | grep -v WP_CACHE_KEY_SALT | cut -d \' -f 4)
echo "Database Password: $dbpass"

echo "Creating database: $dbname"
mysql -e "CREATE DATABASE $dbname;"

echo "Assigning Database User: $dbuser to Database: $dbname using Password: $dbpass"
/usr/bin/mysql -e "grant all privileges on $dbname.* to $dbuser@'localhost' identified by '$dbpass';"

Did this answer your question?