Enabling MySQL general query log with JDBC

后端 未结 5 1281
傲寒
傲寒 2020-12-06 05:26

Is there a way to enable MySQL general query logging through JDBC? The closest thing I have found through my search is the ability to log slow queries through JDBC (http://d

5条回答
  •  無奈伤痛
    2020-12-06 05:56

    I ended up finding a workaround. I enable MySQL general query logging through Java by modifying MySQL global system variables at runtime with the following SQL queries.

    SET GLOBAL log_output="FILE"
    SET GLOBAL general_log_file="Path/File"
    SET GLOBAL general_log='ON'
    

    I recommend using forward slashes in the general_log_file path. I could not get backslashes to work, even in a Windows environment.

    I disable general query logging at runtime with the following SQL query.

    SET GLOBAL general_log='OFF'
    

提交回复
热议问题