mysql docker connection error: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

I started docker mysql container and try to connect it outside docker using mysql command but got error:

It's because mysql clinet will use unix socket protocol as default protocol value to connect to mysql server if not specifying protocol or host argument, but mysql docker container is listening on tcp socket.


Specify IP address as host argument value in mysql command will make mysql to connect using TCP protocol instead of default unix socket.
(Note that using localhost as host argument value will still using unix socket protocol)

Or use

This command will specify protocol argument explicitly

Specified key was too long; max key length is 3072 bytes

When running above SQL statement to add an unique index, following error happened.

[2018-03-28 11:38:24] [42000][1071] Specified key was too long; max key length is 3072 bytes


The actionstatistics table structure is defined as following:

So the length of above index key I'm trying to create is value(255*3), productId(4), productName(255*3), productSerialNumber(255*3), userPhone(255*3), userName(255*3), userId(8), type(255*3), statStartTime(8), statEndTime(8)

Total length is 255*6*3 + 4 + 8*3=4618 is exactly greater than 3072 bytes.


You may notice when calculating the bytes length, we multiply 3 for the varchar type, that's because charset of actionstatistics table is UTF8, so every character will occupy 3 bytes.



One solution is to decrease length of each key. Now I'm using 255 as key length for each varchar column, but that's wasting of disk space. Since columns like userPhone, userName, etc. don't need occupy 255 bytes space.

So change to following statement, and the error is fixed.


Another solution is to increase this 3072 bytes max key length limit.

MySQL find all MyISAM tables

The information_schema table saves information about databases, tables, columns, indexes and triggers, etc.


To list all MyISAM tables, we can use following SQL


And to find MyISAM tables in database wordpress


Next filter them with a table prefix wp_

MySQL Auto Backup

First create a shell script which is used to backup database, here we named the script as

In above command, we use date command to generate current date, and use it as part of filename.

After that we need to make this file executable


To make this backup script run automatically, we should create a cronjob. Type following command to open cronjob editor

crontab -e

Write following text and save it

Above command means the cronjob will run at 0:00 everyday



Check MySQL case-insensitive query or table name

I tried to install Umbrao CMS, it supports MySQL database but it need MySQL to support case-insensitive query and table name.


Following is way to check whether case-insensitive query is supported:

show variables where variable_name='lower_case_table_names';

or check lower_case_table_names option in my.ini (MySQL configuration file)


If this option's value is set to 1, then case-insensitive query and table name is supported.