Bobcares

MariaDB Default Collation | What All To Know About?

by | Aug 6, 2022

MariaDB default collation provides incredibly precise control over all the character sets and collations in our data. At Bobcares, with our Server Management Service, we can handle your MariaDB issues.

MariaDB Default Collation

The rules for comparing and sorting a specific character set are known as collation. In MariaDB, the default collation is latin1_swedish_ci. For instance, a subset of a character set could consist of the letters A, B, and C. A default collation could define these as appearing in descending order of C, B, and A.

Considering different case characters will add more complexity. The characters A and a would be evaluated differently in a binary collation, resulting in a specific ordering. However, a case-insensitive collation would evaluate ‘A’ and ‘a’ as the same. While each collation is only associated with one character set, a character set can be associated with many collations.

MariaDB supports many collations, including big5_chinese_ci, big5_bin, big5_chinese_nopad_ci, big5_nopad_bin, dec8_swedish_ci and so on. Collations that have a ‘ci’ at the end of their names are case-insensitive. Collations that have a ‘cs’ at the end of their names are case sensitive. If the name contains the word “nopad,” it means that the collation is of type NO PAD rather than PADSPACE. NO PAD collations regard trailing spaces as normal characters.

Viewing MariaDB Collation

We can definitely see the supported collation on our server with the SHOW COLLATION commands. The entire collation list is also provided on the MariaDB official site.

SHOW COLLATION command: The output from SHOW COLLATION includes all available collations. Syntax is:

SHOW COLLATION
    [LIKE 'pattern' | WHERE expr]

EXAMPLE

SHOW COLLATION LIKE 'latin1%';
+-------------------+---------+----+---------+----------+---------+
| Collation         | Charset | Id | Default | Compiled | Sortlen |
+-------------------+---------+----+---------+----------+---------+
| latin1_german1_ci | latin1  |  5 |         | Yes      |       1 |
| latin1_swedish_ci | latin1  |  8 | Yes     | Yes      |       1 |
| latin1_danish_ci  | latin1  | 15 |         | Yes      |       1 |
| latin1_german2_ci | latin1  | 31 |         | Yes      |       2 |
| latin1_bin        | latin1  | 47 |         | Yes      |       1 |
| latin1_general_ci | latin1  | 48 |         | Yes      |       1 |
| latin1_general_cs | latin1  | 49 |         | Yes      |       1 |
| latin1_spanish_ci | latin1  | 94 |         | Yes      |       1 |
+-------------------+---------+----+---------+----------+---------+

Changing MariaDB Collation

We can configure collations for client-server communication as well as from the server level down to the column level. Consider the code:

SET collation_connection = latin1_german2_ci;

SELECT 'Mueller' = 'Müller';
+-----------------------+
| 'Mueller' = 'Müller'  |
+-----------------------+
|                     1 |
+-----------------------+

The same two characters will evaluate as equivalent if the connection character set changes to latin1_german2_ci, or German phone book, using the collation_connection system variable.

Illegal Collation Mix

In MariaDB 10.1.28, we may encounter Error 1267 when performing comparison operations in views on tables that use binary constants. For instance,

CREATE TABLE test.t1 (
   a TEXT CHARACTER SET gbk 
) ENGINE=InnoDB 
CHARSET=latin1
COLLATE=latin1_general_cs;

INSERT INTO t1 VALUES ('user_a');

CREATE VIEW v1 AS
SELECT a <> 0xEE5D FROM t1;

SELECT * FROM v1;
Error 1267 (HY000): Illegal mix of collations (gbk_chinese_ci, IMPLICIT)
and (latin_swedish_ci, COERCIBLE) for operation

The binary character changes to a string literal by MariaDB when the view query writes to the file. Thus leading to confusion when the SELECT statement is used. If we run into this problem, we should force the character set in the view to be what we want. This error by MariaDB is a result of a bug that was in MariaDB 10.1.29. In this circumstance, later releases do not throw errors.

[Looking for a solution to another query? We are just a click away.]

Conclusion

A column without a specified collation will search for the table default, the table for the database, and the database for the server because character sets and collations always cascade down. As a result, we can have incredibly precise control over all the character sets and collations in our data. To summarize, our skilled Support team briefly explains the MariaDB collation details.

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

 

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