How to display a full log of SQL queries executing against a DDEV container
Should you want to display every query running against your database, DDEV does not (rather rationally) have any built-in feature for this.
What we will do is to tell MariaDB to record all the queries to it’s log file, and then watch that file. There are a couple catches - for example, you have to be root to read the log by default. Substitute your DDEV’s project name as appropriate.
- Given you have a running ddev, log into the mysql container with root db access:
ddev mysql -u root -p
(password is also root, by default). - Set SQL to record it’s queries by issuing:
SET GLOBAL general_log=1;
- A mariadb.log file will now be created in the DB container at
/var/lib/mysql/{projectname}-db.log
. To view it, you’ll have to be root in the container (whichddev ssh
won’t get you), so we’ll use docker directly:docker exec -u root -it ddev-{projectname}-db /bin/bash
. Once in the container, you can now dotail -f /var/lib/mariadb/{projectname}-db.log
. - As the log file is in the container, there’s no need to clean up - and also be aware that e.g.
ddev stop
will remove the container, along with the log and the setting to record it.
For additional MariaDB logging options, see their documentation