DEV Community

Heddi Nabbisen
Heddi Nabbisen

Posted on

MariaDB: Update database charset / collation

I made a mistake when I made a MariaDB database for a WordPress website.

The website would use Japanese and therefore the database charset should have been set "utf8mb4" as. I, however, did CREATE DATABASE without specific options and so it was "c" instead of "utf8mb4" unfortunately.

I updated its charset and collation with this SQL:

-- accessing through `mysql -u <user> -p`
ALTER DATABASE <database> \
    CHARACTER SET='utf8mb4' \
    COLLATE='utf8mb4_unicode_ci' \
    ;
Enter fullscreen mode Exit fullscreen mode

Well, it is also able to get charsets via SQL:

SELECT SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME \
    FROM information_schema.SCHEMATA;
Enter fullscreen mode Exit fullscreen mode

Reference:

Discussion (0)