Score:0

mysql_install_db wrong charset and collation

in flag

I am creating a new server with the mysql_install_db tool. It sets the correct datadir, port, password, service etc. But My problem is that the charset and collation of my base tables are wrong. They need to be utf8mb4 and utf8mb4_general_ci.

I can't find a way to change these tables with the installation. When I change my.cnf/my.ini it only changes for newly created databases. But Since mysql_install_db creates the system databases, they are created wrong.

It also looks like my msyql_install_db.exe does not accept a defaults-file argument.

Something else is also weird. If I run the command to create a new database, it will also use utf8mb3 while I explicitly set the COLLATE to utf8mb4_unicode_ci.

CREATE DATABASE IF NOT EXISTS tt DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

I am using mariadb 10.6.4 which is the latest version.

Anyone knows how to setup the correct charset and collation to the system databases?

Tools\mariadb-winx64\bin\mysql_install_db.exe --datadir="Tools\mariadb-data" --password=PASSWORD --port=8137 --service=MyDB

enter image description here

[Update]

I tried to setup my.cnf with the following, but seems to take no effect: https://stackoverflow.com/questions/3513773/change-mysql-default-character-set-to-utf-8-in-my-cnf

Also tried using a different way with initializing-insecure, but also the same results. I created a my.cnf with the correct encoding, but still got the wrong table encoding:

mariadb-winx64\bin\mariadbd.exe --defaults-file=./my.cnf --initialize-insecure --datadir=./Test

And my.cnf

[client]
default-character-set=utf8mb4


[mysql]
default-character-set=utf8mb4

[mysqld]
skip-grant-tables
port = 5137
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
Score:1
ua flag

Do not worry about the system-generated tables (information_schema, etc). Any attempt to modify them could lead to serious problems.

True, it makes sense for them to be utf8mb4, not utf8mb3. But leave that conversion up to the developers of MySQL and MariaDB to fix (someday).

It is probably best for your tables and connections to be utf8mb4. But you do have control over them.

in flag
The problem is, is that I use the .NET connector, which does not support UTF8MB3, and I want to see if a database exists. Where I need the system tables.
ua flag
@Niels - `utf8mb3` is a synonym for `utf8`. They should be interchangeable. You _cannot_ use `utf8mb4_unicode_ci` with either. The first part of the collation must match the character set.
ua flag
@Niels - and you can `SELECT` a utf8mb3 table even when `SET NAMES utf8mb4` in effect. Maybe I am lost as to where the problem is.
in flag
I removed my `SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = @name` query and just do a `CREATE DATASE IF NOT EXISTS`. So I don't need to read from the utf8mb3 tables.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.