Skip to content

Instantly share code, notes, and snippets.

@je8n
Created July 20, 2018 20:54
Show Gist options
  • Save je8n/0f68e1042f1215a8d2cef51615e07cd9 to your computer and use it in GitHub Desktop.
Save je8n/0f68e1042f1215a8d2cef51615e07cd9 to your computer and use it in GitHub Desktop.
linux foreach import several sql files in folder with mysql terminal
#query: mysql-u[username] -p[password] -e [query]
for SQL in *.sql; do DB=${SQL/\.sql/}; echo importing $DB; mysql -uroot -p -e "create database $DB"; done
# first create filenames database
for SQL in *.sql; do DB=${SQL/\.sql/}; echo importing $DB; mysql -uroot -p $DB < $SQL; done
#import file to filename database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment