Bash Execute Multiple MySQL Commands from Shell

Posted on May 18, 2017 at 10:07 am

Here is a Bash script to run multiple MySQL commands:

#!/bin/bash
 
mysql -u root -p'YOUR_MYSQL_PASSWORD_HERE' dbname << eof
ALTER TABLE site DROP INDEX name, ADD UNIQUE KEY email (email);
ALTER TABLE site DROP INDEX name_index;
alter table site drop column users;
alter table site drop column downloads;
alter table site drop column invoices;
alter table site drop column stats;
eof

You can run the script in background like this:
Run Linux Bash Script in Background

Other Posts

Updated Posts