About Running SQL Queries from a Bash Script

You can run SQL queries from a bash script like this:

1
2
3
4
5
6
SQL=$(cat << EOM
TRUNCATE TABLE django_session;
EOM
)
echo $SQL | python manage.py dbshell \
--settings=myproject.settings.local

This logs out all users from a Django website.

Tips and Tricks Dev Ops Django 4.2 Django 3.2 Django 2.2 MySQL Bash