Bobcares

MySQL dump error ‘illegal mix of collations’ – How to resolve

by | Jun 4, 2021

Wondering how to resolve MySQL dump error ‘illegal mix of collations’? We can help you.

As part of our Server Management Services, we assist our customers with several MySQL queries.

Today, let us see how our Support Techs fix this error.

 

What causes MySQL dump error ‘illegal mix of collations’?

Typical error might look as shown below:

Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

This error generally occurs by comparing two strings of incompatible collations or by attempting to select data of different collations into a combined column.

In this case, they are utf8_unicode_ci and utf8_general_ci.

Hence, we need to make the two columns collation match.

 

How to resolve it?

Let us see some of the steps followed by our Support Techs to resolve the issue.

1. Change the collation of one column (or string) to match the other collation.

Find the columns with inappropriate collation:

SHOW CREATE TABLE table_name;

So the chances are, you can find the column with a different collation or it hasn’t been specified at all.

Then, you can change the collation on each column:

ALTER TABLE table_name CHANGE col_name data_type CHARACTER SET charset_name COLLATE collation_name;

If you want to make a collation change table-wide:

ALTER TABLE table_name CONVERT TO CHARACTER SET charset_name COLLATE collation_name;

 

2. Add a COLLATE clause to specify the collation used in your query.

SELECT * FROM table _name ORDER BY col_name COLLATE collation_name;
3.Generate ALTER TABLE command into sql file and execute sql file on database. a.Generate ALTER TABLE command into sql file: SELECT CONCAT("alter table `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` convert to character set utf8 collate utf8_general_ci;") as MySQLCMD
INTO OUTFILE "/var/tmp/test_schema_update.sql"
FROM information_schema.TABLES WHERE TABLE_SCHEMA = "test" The SELECT ... INTO OUTFILE 'file_name' form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed. As alternative if you are using Virtual machine or Docker container you could use client command such as mysql -e to generate file on local environment: mysql -h172.17.0.1 -uroot -e 'SELECT CONCAT("alter table `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` convert to character set utf8 collate utf8_general_ci;") as MySQLCMD FROM information_schema.TABLES WHERE TABLE_SCHEMA = "test"' > /var/tmp/test_schema_update.sql b.

To execute generated file please use below command:

mysql -h172.17.0.1 -uroot dbname < /var/tmp/test_schema_update.sql

If you have got such error:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘MySQLCMD
alter table `dbname`.`tablename` convert to character set utf8 collate ‘ at line 1Just open test_schema_update.sql file and remove MySQLCMD string from the very beginning and save. After that try again to import file to your database.

 

Change the collation from command line.

Let us go through the steps followed by our Support techs to change the collation from command line.

  • Log into MySQL with SSH:
mysql -u admin -p`cat /etc/psa/.psa.shadow`
  • Enter your database password when prompted.
  • Run the following command to change the character set and collation of your database:
ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
  • Run the following command to change the character set and collation of your table:
ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;

For either of these examples, please replace the example character set and collation with your desired values.

[Finding it hard to fix MySQL error? We’d be happy to assist you]

 

Conclusion

In short, today we saw steps followed by our Support Techs to resolve this MySQL error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF