Friday, 16 November 2018

How to enable the MySQL Slow Query log in ubuntu

When developing your own internet application its necessary that pages load quickly. The most important factors that confirm page response times is that the time taken to SQL queries, however does one recognize that SQL queries at fault?

The answer is MySQL's slow question log. By facultative this feature, a log file is formed which will tell you on every time a query takes too long to execute. you'll be able to then use this data to either optimize your info or rewrite the SQL.

For this guide i'll assume you have already installed MySQL or MariaDB. These article is supporting Ubuntu 16.04 however the identical approach works on different UNIX operating system.

Step 1: modify the Slow question log

First, confirm your MySQL configuration file "my.cnf" is located - on Ubuntu 16.04 it's /etc/mysql/my.cnf whereas on different distributions it's typically /etc/my.cnf

Edit the MySQL configuration file and add the subsequent lines at the end:

 slow_query_log_file = /var/log/mysql/slow.log  
 long_query_time = 1  

Save your changes and restart MySQL

 service mysql restart  

Step 2: examining the slow question log

Start looking the slow log:

 tail -f /var/log/mysql/slow.log  

At startup, you may see output like this:

 /usr/sbin/mysqld, Version: 5.7.12-0ubuntu1-log ((Ubuntu)). started with:  
 Tcp port: 3306 OS socket: /var/run/mysqld/mysqld.sock  
 Time Id Command Argument  

Now, mistreatment your browser begin interacting together with your internet application and note the queries that are shown. shortly you will notice one or 2 queries that are systematically shown.

Wednesday, 2 September 2015

How can I create a archive/zip of a whole directory via terminal?

Create Zip file using Ubuntu command
Create Zip file using Ubuntu command

For creating the zip you have installed zip. For installing zip execute the below command to terminal

 sudo apt-get install zip  

After the install the zip executes the below command into the terminal for creating zip files

 zip -r myfiles  

-r (recursive) –r  option is zip whole directories and files trees at once

 myfiles is the directory path which needs  to convert into a zip file.

produced zip name of the zip which have the directory structure as well as the files .

You can also tell where the zip file will. Here is the example /home/ubuntu/, will store at home /home/ubuntu/ path.

 The zip command comes with documentation telling you about all of its (many) options; type
 man zip  
to see that documentation.

Wednesday, 19 August 2015

How to send email using the phpMailer

PHPMailer is a code files are use for send emails safely and easily using PHP code.  Sending emails directly via PHP code using SMTP protocol.

Features of phpMailer
  • Debugging feature
  • Send plain, HTML, and Multipart batched files Mail
  • Send Mail using SSL, TLS
  • SMTP, POP3

Here are steps to use the phpMailer

First, download PHPMailer code with the below link

After downloaded the file unzip / extract it to your project / root folder. In my case I have put files in public_html/PHPMailer/ folder. Now, you need to change web pages to use the PHPMailer code.
For send mail copy and below code and past to your php file

 $mail = new PHPMailer();  
 $mail->IsSMTP();                                     // set mailer to use SMTP  
 $mail->Host = " ";              // specify main and backup server  
 $mail->SMTPAuth = true;                              // turn on SMTP authentication  
 $mail->Username = "<Your UserName>";         // SMTP username  
 $mail->Password = "<Your Password>";                    // SMTP password  
 $mail->From = "";  
 $mail->FromName = "";  
 $mail->AddAddress("", "Nikunj Kansara");  
 $mail->AddAddress("");            // name is optional  
 $mail->AddReplyTo("", "Information");  
 $mail->WordWrap = 50;                               // set word wrap to 50 characters  
 $mail->AddAttachment("/var/tmp/file.tar.gz");  // add attachments  
 $mail->AddAttachment("/tmp/image.jpg", "new.jpg");     // optional name  
 $mail->IsHTML(true);                                 // set email format to HTML  
 $mail->Subject = "Here is the subject";  
 $mail->Body     = "This is the HTML message body <b>in bold!</b>";  
 $mail->AltBody = "This is the body in plain text for non-HTML mail clients";  
   echo "Message could not be sent. <p>";  
   echo "Mailer Error: " . $mail->ErrorInfo;  
 echo "Message has been sent";  

Monday, 3 August 2015

421 Sorry, cleartext sessions are not accepted on this server

I'm trying to access an FTP from my web browser, but I get the following error: 421 Sorry, cleartext sessions are not accepted on this server.
After the searching, I found "421 Sorry, cleartext sessions are not accepted on this server" means that the server is using "FTP over Explicit TLS/SSL".

Filezilla might be a good choice for connecting "FTP over Explicit TLS/SSL"

Here are the steps to connect FTP over the TLS

  • Download Filezilla using the URL
  • Install FileZila into your local machine
  • Click on File Menu >> Site manager
  • Click on the New Site Button
  • Enter the Hostname, port, Username and Password
  • Select the encryption option "Required explicit FTP Over TLS"

  • Click on Ok Button

Tuesday, 9 June 2015

How to optimize MySQL table size

We have to design your tables in such a way to use minimize their space on the disk. This  outcome is reducing to read and write data from disk. Create table  can take very less space, but while their content actively processed at the time of execution query.

MySQL supports many verying storage engines and row format. Choosing the right table format for your application can give you a high performance.

You can get higher performance for a table and minimize storage space by using the techniques listed below

  • Use the smallest data types. MySQL has many specialized types that save disk space and memory. Let’s take example, use the smaller integer types if possible to get smaller tables. MEDIUMINT is often a better choice than INT because a MEDIUMINT column uses 25% less space.
  • Declare columns to be NOT NULL if possible. It makes SQL operations faster

Row Format

  • InnoDB tables use a compact storage format. By default, tables are created in the compact format (ROW_FORMAT=COMPACT). The compact row format reduce row storage space by about 20% at the cost of increasing CPU use for some operations
  • For MyISAM tables, if you do not have any variable-length columns (VARCHAR, TEXT, or BLOB columns), a fixed-size row format is used. This is faster but may waste some space. 


  • Create only the indexes that you need to improve query performance. Indexes are good for retrieval, but slow down insert and update operations. If you access a table mostly by searching on a combination of columns, create a single composite index on them rather than a separate index for each column. The first part of the index should be the column most used. If you always use many columns when selecting from the table, the first column in the index should be the one with the most duplicates, to obtain better compression of the index.

How to save the output of a Linux/Unix command to a file

The Bash / KSH and POSIX shell provides a file redirection option to redirect the output of commands to a file using the following two operators

> is output redirection symbol
>> is append output redirection symbol

The > operator always overwrites existing output files

Syntax to save the output of a command to a file

 command > filename  


Saving the date command output to a file called output.txt

 $ date > output.txt  

In this example, save the output of the date command to a file called output.txt

The >> operator appends the output of a command with the same file as

Syntax to save and append the output of a command to a file

 command >> filename  


Saving and appending the date command output to a file called output.txt

 $ date >> output.txt  

How to find the last day of the month from date in php?

How can I get the last day of the month in PHP?

 $a_date = "2009-11-23"  

I want last day of the month like 2009-11-30

 string date ( string $format [, int $timestamp = time() ] )  

Date function has format string "t", returns the number of days in the month of a given date (see the date document)

 $a_date = "2009-11-23";  
 echo date("Y-m-t", strtotime($a_date));