Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Doctrine run SQL from a file in CLI

I can use this to execute SQL at the CLI

php app/console doctrine:query:sql "SELECT * FROM table"

But how can I use the same command to exec SQL from a file? E.g.

php app/console doctrine:query:sql filename.sql

I have tried > and < in various ways and cat but nothing even comes close to doing what I want.

I realised I can use straight mysql to do this, but I wish to do it via doctrine.

like image 635
Jake N Avatar asked Mar 09 '16 17:03

Jake N


People also ask

How do I run a .SQL file from MySQL command line?

use the MySQL command line client: mysql -h hostname -u user database < path/to/test. sql. Install the MySQL GUI tools and open your SQL file, then execute it.


2 Answers

php app/console doctrine:query:sql "$(< filename.sql)"
like image 149
Paweł Mikołajczuk Avatar answered Oct 05 '22 12:10

Paweł Mikołajczuk


With a current Symfony/Doctrine version you can easily run:

php bin/console doctrine:database:import [files]

like image 38
althaus Avatar answered Oct 05 '22 11:10

althaus