How to enable MariaDB/MySQL logs ?
As a web developer that have been toying with MySQL/MariaDB for more than 5 years. I can tell you that the best way to start debugging your application or looking for ways to improve database performance is to enable the logs. To enable the MySQL/MariaDB logs :
Edit MySQL configuration file:
vi /etc/mysql/my.cnf
Note : Depending on your installation, the my.cnf file could be located on different directory. MariaDB's my.cnf is located at /etc/my.cnf
Slow Query Log
To enable Slow Query Log, add these lines or uncomment these two lines. Change the destination location for the log files if you prefer.
logslowqueries = /var/log/mysql/mysql-slow.log
longquerytime = 2
log-queries-not-using-indexes
To enable Error Log, add these lines or uncomment these two lines. Change the destination location for the log files if you prefer.
[mysqld_safe]
logerror=/var/log/mysql/mysqlerror.log
[mysqld]
logerror=/var/log/mysql/mysqlerror.log
To enable General Query Log, add these lines or uncomment these two lines. Change the destination location for the log files if you prefer.
generallogfile = /var/log/mysql/mysql.log general_log = 1
To enable these changes, restart mysql
sudo /etc/init.d/mysql restart
or
sudo service mysql restart
References :
http://dev.mysql.com/doc/refman/5.7/en/slow-query-log.html
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.9k Golang : Lock executable to a specific machine with unique hash of the machine
+16.8k Golang : Gzip file example
+24.8k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+14.4k Golang : Get uploaded file name or access uploaded files
+20.6k nginx: [emerg] unknown directive "passenger_enabled"
+5.7k Golang : Detect words using using consecutive letters in a given string
+20.3k Golang : Count number of digits from given integer value
+8.5k Golang : How to check if input string is a word?
+9.7k Golang : How to extract video or image files from html source code
+33.9k Golang : convert(cast) bytes to string
+30.2k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+12k Golang : Convert decimal number(integer) to IPv4 address