Here’s a one-liner to run a SQL command on all tables in a database:
1 2 3 |
mysql -h localhost --password=mypassword -u root -Nse 'show tables' mydb \ | while read table; do mysql -h localhost -p --password=mypassword -u root \ -e "show create table $table" mydb; done |
- Replace “show create table” with the command that you wish to execute.
- Replace “mydb” with your database name.
- Replace “root” and “mypassword” with you username and password.
- Replace “localhost” with your database server hostname or IP address.