Skip to content

Database Logging

MySQL Logging

  • Enable Loggin and Replication in /etc/mysql/my.cnf
    [mysqld]
    ...
    general_log_file = /var/log/mysql/mysql.log
    general_log = 1
    
  • Restart MYSQL
    sudo systemctl restart mysql
    
  • Check the log file
    sudo tail –f /var/log/mysql/mysql.log
    

or Login as root to MySQL and execute

SET global general_log_file='/tmp/mysql.log'; 
SET global log_output = 'file';
SET global general_log = on;

PostgreSQL Enable Database Logging

Look for postgresql.conf file to edit

log_statement = 'all' # none, ddl, mod, all

### Windows

Restart the Application to apply the new settings. We can do this by launching services.msc from the Runcommand window and finding the Applications service

Find failed queries in the log file

C:\Program Files (x86)\ManageEngine\AppManager12\working\pgsql\data\amdb\pgsql_log\

### Linux Restart postgresql

sudo systemctl restart  postgresql

Check the logs

sudo tail -f /var/log/postgresql/postgresql-10-main.log

MariaDB Query Debugging

  1. Edit mysql.log to enable loggin
    sudo nano /etc/mysql/my.cnf
    
[mysqld]
...
general_log_file    = /var/log/mysql/mysql.log
general_log     = 1
  1. Restart mysql

    sudo systemctl restart mysql
    

  2. Tail the log file

    sudo tail -f /var/log/mysql/mysql.log
    


PHP apache2 Logging

Enable the PHP display_errors directive

  • Modify /etc/php5/apache2/php.ini
  • Append the following lines to the file
    display_errors = On
    
  • Restart apache2
    sudo systemctl restart apache2