Reputation: 2111
to run a single file you can run in mysql
.\ filename
or you outside of mysql you can run
mysql < filename
I have a directory of sql files so I'm trying to run them all at once by using a wildcard
*.sql
but it doesn't work.
Any ideas?
Upvotes: 29
Views: 47062
Reputation: 1
cat *.sql | mysql -u root -p "database name"
you can change root with your username and if you have password you can add your password behind -p
i hope this help
Upvotes: 0
Reputation: 111
For Windows:
FOR %%A IN ("*.sql") DO "D:\mysql\Install\MySQL Server 5.5\bin\mysql" --user=scooby --password=pwd123 databasename < %%A >output.tab
Upvotes: 11
Reputation: 2067
bash:
for sql_file in `ls /path/to/directory/*.sql`; do mysql -uUSER -pPASSWORD DATABASE < $sql_file ; done
Upvotes: 7
Reputation: 121
for %S in (*.sql) do mysql -u user_name database_name < %S
or
mysql -u user_name -p password database_name < file.sql
Upvotes: 12