Wednesday, March 29, 2023

Turning On Mysql Slow Query Log

Slow query log is a mechanism in mysql which will track and record queries that take long time to complete, for database administrator to analyze and optmize to increase mysql performance.

To check if this feature is already turned on, we can run below command in mysql console:
mysql> show variables like 'slow_query_log';

We will see something like below if it is already turned on: 

The query will be deemed slow, of the query takes longer than 'long_query_time' to complete. We can also check this using below command:
mysql> show variables like 'slow_query_log';

In this case, our long_query_time is set to 10 seconds:

We can check the location of the slow_query_log_file by using below command:
mysql> show variables like 'slow_query_log_file';

In this example, the log file is located in /bitnami/mysql/data/5653c641c26b-slow.log

The above variables, can be set in the runtime using below commands:

To turn off slow_query_log
mysql> set global slow_query_log = off;

To set long_query_time to 5 seconds
mysql> set long_query_time = 5;

All the changes that we made in mysql console, is only for the current runtime, and would not survive mysql service restart. To make the changes permanent, we need to modify /etc/my.cnf, under [mysqld], like below

And then restart mysql
$ sudo systemctl restart mysql

Thursday, March 23, 2023

Checking Disk Read & Write Speed in Linux

We are going to use 2 tools for this, one is called hdparm to test read speed, and the second one is called dd, to test write speed.

First, install hdparm
$ sudo apt install hdparm -y

Then, get the disk name. The name of the disk in below example is /dev/sda.
$ lsblk

Test read speed using hdparm. -t option is to record the timing for the read process. In below example, the read speed is around 700MB/sec.
$ sudo hdparm -t /dev/sda

To test write speed, we will use dd command. dd will write a 1M file called speedtest.img to disk, and the "oflag=direct" option will make dd use direct IO, skipping any filesystem cache. dd will show the disk write speed after it finishes writing the file to disk. In below example, the write speed is 100MB/s.
$ dd if=/dev/zero of=speedtest.img bs=1M count=1 oflag=direct

Wednesday, March 1, 2023

Extract Text From Image Using Command Line

The tool to use for this task is called tesseract.

To install tesseract in any ubuntu derivatives, just run below command
$ sudo apt install tesseract-ocr -y
To extract text from an image file called 007.png, run below command
$ tesseract 007.png 007output
007output is the output file, and an extension of .txt will always be put to the output file.

To view the output, just use cat like below
$ cat 007output.txt