Bobcares

WeSupport

Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 11.06 minutes in March 2021 to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

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 *

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

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

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

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