InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Mysql tutorials

  • Enable query log without restarting mysql on Linux
  • How to find mysql query rate on Linux
  • Mysql - display row count and size of tables
  • Mysql - get size of all databases
  • Mysql - get total queries since beginning
  • Mysql - how to copy a table
  • Mysql - how to enable query log
  • Mysql 5.7 root password after installation
  • Mysql difference between CURDATE() and NOW()
  • Mysql find current timezone offset
  • Mysql find slave lag
  • Mysql how to dump schema of all databases
  • Mysql multi column Index
  • Wordpress Mysql Queries
  • mysql - how to enable query logs
  • mysql find recently created-tables
 
  • Home
  • > Tutorials
  • > Mysql

Mysql – how to enable query log

By admin on Nov 15, 2015

It may be useful to enable mysql query log on development of even production server for a short duration for debugging or code/flow analysis purpose. Here are the steps for enabling mysql query log on Ubuntu Linux. The similar instructions can be used on other Linux flavours also.

First locate [mysql] section inside /etc/mysql/my.cnf. You will have to use sudo to edit the config file. Add the following line:

[mysqld]
...
...
...
## Log all queries.
log=/var/log/mysql/query.log

Note that this can fill up disk space fast. So avoid doing it permanently in production.

Now restart mysql, visit some page on site which will cause some mysql queries and check the log file as shown below:

$ sudo service mysql restart
$ sudo chmod a+r /var/log/mysql/query.log
$ tail -f /var/log/mysql/query.log

For a wordpress site, you should see something like this in query.log when you visit home page:

151115 18:11:55	    9 Connect	SOMEUSER@localhost on 
		    9 Query	SET NAMES utf8mb4
		    9 Query	SELECT @@SESSION.sql_mode
		    9 Init DB	DBNAME
		    9 Query	SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'
		    9 Query	SELECT option_value FROM wp_options WHERE option_name = '_transient_timeout_facebook_locale' LIMIT 1
...
...
...

Suggested posts:

  1. Chrome – copy any request as cURL including headers
  2. mysql find recently created-tables
  3. WordPress themes for beginners worth considering
  4. How to kill unresponsive ssh session using escape sequence
  5. SVG – beginner tutorial
  6. Curl – follow redirects
  7. jQuery – difference between html() and text()
  8. HTML li tag
Share this article: share on facebook share on linkedin tweet this submit to reddit
| Tagged Linux, Linux/Unix Command Line, Mysql, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress