DEV Community

nabbisen
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:

Top comments (0)

50 CLI Tools You Can't Live Without

The top 50 must-have CLI tools, including some scripts to help you automate the installation and updating of these tools on various systems/distros.