How to run the same SQL Script (MySQL) on all the banks of my Server?

0

I have several Wordpress sites hosted inside the same server (I am an Agency) and I created a Script that creates users in the Bank of Wordpress so that each employee of the company can access each site with its individual login, since we currently have only one login in common for all hits.

However, I need to go into each Bank individually, through PHPMyAdmin, and run the Script.

Is there a way to automate this process and run it all at once?

    
asked by anonymous 13.09.2018 / 13:42

1 answer

0

You can have your SQL script run through the shell command line, and then you can make a for in the shell script and run at once for all the databases in your table.

This is an example script to run the SQL script on all created databases:

DBS="$(mysql -u root -pPASSWORD -h localhost --silent -N -e 'show databases')" 
SESSION_LOG="/tmp/$$.log"

backup(){

for DB in $DBS; do
    mysql -u root -pPASSWORD -h localhost $DB < script_db.sql
done
    clean
}

backup > $SESSION_LOG
    
13.09.2018 / 14:18