1

MySQL query logging - stitcher.io

 3 years ago
source link: https://www.stitcher.io/blog/mysql-query-logging
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
MySQL query logging
By continuing your visit to this site, you accept the use of cookies. Read more.

Scout APM helps PHP developers pinpoint N+1 queries, memory leaks & more so you can troubleshoot fast & get back to coding faster. Start your free 14-day trial today.

« back — written by Brent on January 20, 2018

MySQL query logging

# Enable query logging

mysql -p -u root

> SET GLOBAL general_log = 'ON';

# Turning it off again when finished

> SET GLOBAL general_log = 'OFF';

# Find the log file

First, find the mysqld process ID.

ps auxww | grep mysql

brent             2042   0.0  0.4  2849776  67772   ??  S    Fri11AM   0:16.80 /usr/local/opt/mysql/bin/mysqld

Second, use lsof to find all files used by this process, and filter on log.

# sudo lsof -p <PID> | grep log

sudo lsof -p 2042 | grep log

mysqld  2042 brent    4u     REG                1,4  50331648  780601 /usr/local/var/mysql/ib_logfile0
mysqld  2042 brent    9u     REG                1,4  50331648  780602 /usr/local/var/mysql/ib_logfile1
mysqld  2042 brent   26u     REG                1,4        35  780672 /usr/local/var/mysql/mysql/general_log.CSM
mysqld  2042 brent   32r     REG                1,4         0  780673 /usr/local/var/mysql/mysql/general_log.CSV
mysqld  2042 brent   33w     REG                1,4     25504 9719379 /usr/local/var/mysql/HOST.log

/usr/local/var/mysql/HOST.log is the one you want, HOST will be the name of your host.

tail -f /usr/local/var/mysql/HOST.log

Next up:  Curly brace placement

Follow me: TwitterRSSNewsletterPatreonGitHub

© 2020 stitcher.io — Cookies & Privacy


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK