How to convert MySQL collation from utf8mb4 to utf8

Recently I faced a tough situation with one of my WordPress site at the time of exporting MySQL database. My development MySQL server supports utf8mb4 collation but the production MySQL server does not support that. So, I had to convert all the tables of the MySQL database from  utf8mb4 to utf8.  The actual task was conversion from utf8mb4_unicode_ci to utf8_general_ci

I tried to convert manually several times but it did not work. My question was what is the difference between utf8mb4 and utf8?

utf8mb4 (as well as standard UTF-8) can directly store any character specified by Unicode; the former is fixed size at 4 bytes per character whereas the latter is between 1 and 4 bytes per character.

utf8 can only store the first 65,536 codepoints, which will cover CJVK (Chinese, Japanese, Vietnam, Korean), and use 1 to 3 bytes per character.

So, the real process will be ALTER the database as well as each database table to change the CHARACTER SET.  Using a PHP script I made the conversion and it worked perfectly. This is the PHP script which will convert your MySQL database collation from utf8mb4_unicode_ci to utf8_general_ci instantly. 

  1. Copy the above PHP script and paste in a file say, ‘dbconversion.php’.
  2. Now put this file in your server (development/production).
  3. Run this script from ‘yourdomain.com/dbconversion.php’.
  4. It’s all. It will convert everything and you will get a success message.

Note: If you are using WordPress website and you need to convert your database any time, make sure ‘utf8’ Charset will be defined in your ‘wp-config.php’ file as
define(‘DB_CHARSET’, ‘utf8’);

Continue Reading

The smartest umbrella ever

Rainy seasons and you always need an umbrella keeping with you always. We struggle always to open or close our umbrella. What if the umbrella will have too much smart to do everything automatically! Yes, it is true to come.

This smart umbrella has the following features.

  1. Automatic open and close with one button push.
  2. Synced with our smart phones.
  3. Bluetooth connectivity so you can not loose it. It will send you notification in your smart phone if you keep it any place and forget to take.
  4. Weather forecasting.

This smart umbrella is a project of Indiegogo and you can purchase this lovely umbrella from their Indiegogo or support them.

Continue Reading

Install Evernote on Linux

Evernote is the most popular work space application nowadays and you can keep anything of your mind like notes, images, audio/video clips, web bookmarks, web clips for your use. Aprt from web version Evernote provide beautiful tool for Windows and MAC. But for Linux users? Yes, you can install Evernote on Linux too. The Linux version is called Everpad. Here is the process to install on Linux.

Press Ctrl+Alt+T on your keyboard to open terminal. When it opens, run command below to add the PPA:
sudo add-apt-repository ppa:nvbn-rm/ppa
Then update and install this app:
sudo apt-get update;
sudo apt-get install everpad
Once installed, open Everpad from Unity Dash.
Continue Reading

Count your wordpress search results

The default WordPress search results page is noting but to show you the total results as per your search keywords. You can spice this page up a bit by showing the total search count like
4 Results found or something like this….

Just you need to add some codes and it will look like the image below.

The main code which do this action is:

<?php $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; ?>

Now what you will have to do is as follows.

Step 1: Open search.php page inside your theme folder. Remove the existing search query and put the following code.

Step 2: Save the file and check the updates doing some search.

If you are new to WordPress theme modification then make sure you will not basic WordPress template function like header, sidebar and footer as get_header(); get_sidebar(); and get_footer();

You can modify the code for style purpose or adding more ingredients on search.

Continue Reading