Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run multiple sql files in mysql batch

Tags:

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?

like image 767
makstaks Avatar asked Mar 16 '10 22:03

makstaks


People also ask

How do I run multiple SQL files at once in SQL Server?

Make sure you have SQLCMD enabled by clicking on the Query > SQLCMD mode option in the management studio. Suppose you have four . sql files ( script1. sql,script2.

How do I import multiple SQL files into MySQL workbench?

Import Multiple SQL files to Database by using Data Import/Restore in MySQL Workbench is great feature when you need to import multiple SQL files into MySQL Server. If you have created multiple files by using Data Export feature in MySQL Server, SQL Dump file project can be imported by using MySQL Import/Restore.


2 Answers

Assuming you're using bash:

cat *.sql | mysql

like image 60
Etienne Dechamps Avatar answered Oct 13 '22 23:10

Etienne Dechamps


for %S in (*.sql) do mysql -u user_name database_name < %S 

or

mysql -u user_name -p password database_name < file.sql 
like image 27
Anuchit Avatar answered Oct 13 '22 23:10

Anuchit