by dashezup · 5y ago · 0 comments
sqlite3 database.db <query.sql
Some other DBMS have similar things, for MariadDB you could write it in a ".sql" file as well, setting variables and use it so that you can write a generic sql file. (seems you can't use the variable thing with sqlite3) MariaDB> SET @username='UserName@localhost';
MariaDB> SET @hostname='localhost';
MariaDB> SOURCE create-user.sql;
Such things is usually cleaner/simpler than writing in bash.You could also read the contents of the query file into a shell parameter with the `read` builtin.