Category Archives: MySQL

Configure MySQL 5.6 LONGBLOB for large binary data

The reason for this issue is a change in MySQL 5.6.20 as one could read in the change log:

As a result of the redo log BLOB write limit introduced for MySQL 5.6, the innodb_log_file_size setting should be 10 times larger than the largest BLOB data size found in the rows of your tables plus the length of other variable length fields (VARCHAR, VARBINARY, and TEXT type fields). No action is required if your innodb_log_file_size setting is already sufficiently large or your tables contain no BLOB data.

Set or increase the value of the innodb_log_file_size option in my.ini below the [mysqld] section. Its default value is 48M. Setting it to

Be careful when changing the value of innodb_log_file_size. Follow these steps to do this safely:

  • Shut the server down cleanly and normally.
    Shutting down MySQL may not be as simple as just service mysql stop!
    Following things should be done to shut down mysql server normally and cleanly:

    1. Double check the instance you are going to shutdown!!
    2. Stop Replication
    3. Flush the dirty pages
    4. Check the long running transactions
    5. Dump and reload the buffer pool
  • Move away (don’t delete) the log files, which are named ib_logfile0, ib_logfile1, and so on.
  • Check the error log to ensure there was no problem shutting down.
  • Then restart the server and watch the error log output carefully.
    • There should see InnoDB print messages saying that the log files don’t exist. It will create new ones and then start.
  • Verify that InnoDB is working.
    • If it’s working, then the old log files can be deleted.

How to automatically kill slow MySQL queries after N seconds?

Good MySQL related application requires right performance tuning. Without right tuning of MySQL configuration, application connections started failing and application became slowing down.

If you are using persistent connection, there may be so many connections which are running but in ‘Sleep’ mode currently. If you have MySQL >= 5.1, where there is a processlist in the INFORMATION_SCHEMA. Generate the KILL QUERY commands in bulk from within the MySQL client for query running longer than 20 minutes (1200 seconds):

You can do WHERE clauses against the INFO field to look for a specific query, the TIME field against long running queries, or the DB field against a specific database.

To run add this query in crontab, create a shell file with following content:

Shell file with above content will kill all queries running more than 1200 seconds (20 mins).

Here is another variation:

Shell file with above content will kill all queries running more than 1200 seconds (20 mins) with adding all queries in log file and running same log file afterwards.

Resetting forgotten phpmyadmin password

Simply change or reset your MySQL root password in Ubuntu by doing the following:

  1. Stop the MySQL serversudo service mysql stop
  2. Start mysqldsudo mysqld --skip-grant-tables &
  3. Login to MySQL as rootmysql -u root mysql
  4. Change ‘{your_new_password}‘ with your new root passwordUPDATE user SET Password=PASSWORD('{your_new_password}') WHERE User='root';
  5. Kill mysqldsudo pkill mysqld
  6. Start mysqlsudo service mysql start
  7. Login to phpmyadmin as root with your new password