Wednesday, August 28, 2013

Enable log slow query mysql

In order to enable slow query logs for MySQL on your system you would need to do the following.
1st Step is to edit your my.cnf file which is located in your /etc directory.
vi /etc/my.cnfPlain Text
Once you have your my.cnf file open, then add the following 4 lines then save and exit the file.
[mysqld]
log-slow-queries
log-slow-queries=/var/log/mysql/slow-queries.log
long_query_time=1
Plain Text
Then create the file slow-queries.log. You can have the file in any spot you wish, as long as you define the path in your my.cnf.
touch /var/log/mysql/slow-queries.logPlain Text
Change the ownership of the file to be owned by MySQL.
chown mysql.mysql /var/log/mysql/slow-queries.logPlain Text
Lastly, you will need to restart mysqld for your changes to take place.
service mysqld restartPlain Text

Now you should have slow query logs enabled catching any MySQL query that took longer then 1 second to process.

Related Posts:

  • Cấp quyền thực thi với sudoMột trong những câu hỏi thường gặp nhất của người mới sử dụng Ubuntu là về sudo. Cơ chế bảo mật này được kích hoạt mặc định trong Ubuntu và mang lại nhiều ưu điểm hơn cơ chế chuyển sang người dùng khác bằng su truyền thống… Read More
  • Các lệnh về fileXóa file và thư mục: -Xóa file: $ rm {name file} $ rm -f {name file}:không hỏi lại có muốn xóa không? -Xóa thư mục: $ rm -rf {name folder} Trong đó -r : Attempt to remove the file hierarchy rooted in each file argument i.… Read More
  • Hiển thị tiến trình trong hệ thống Linux Một trong những công việc cần thiết khi quản trị hệ thống Linux đó là kiểm soát các tiến trình hiện đang chạy. Khi đã biết được những tiến trình nào đang chạy bạn có thể tắt những tiến trình gây giảm tốc độ của hệ thống. Ng… Read More
  • Nano Nano là một trình soạn thảo văn bản dựa trên curse hoạt động trên Unix. Nano vốn dựa trên một bản nhánh (clone) của pico, và là một phần mềm tự do. Nano là một trình soạn thảo rất dễ sử dụng (dễ hơn nhiều so với vi hay em… Read More
  • Clear memory linuxLệnh dùng clear memory cho linux. sync; echo 3 > /proc/sys/vm/drop_caches free -m … Read More