Yes, the character set and byte count (collation) in MariaDB can be changed after initialization, but the process depends on whether you're modifying the server defaults, a specific database, table, or column. Here's how it works:
To modify the default character set and collation for new databases/tables, update the MariaDB configuration file (my.cnf or my.ini) with:
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Restart the server to apply changes. Existing databases/tables retain their original settings.
Use the ALTER DATABASE command:
ALTER DATABASE database_name
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
This affects only new tables created in the database.
Use the ALTER TABLE command:
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
This converts all columns in the table to the new character set.
Specify the character set for a column during creation or alteration:
ALTER TABLE table_name
MODIFY column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
If you initially set latin1 as the default but later need utf8mb4 (e.g., for emoji support), you can convert existing data:
ALTER TABLE users CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
For managed MariaDB services on Tencent Cloud, use TencentDB for MariaDB. It allows easy configuration of character sets during instance creation or via the console. The service also supports online schema changes with minimal downtime.
Note: Changing character sets may require data conversion, which can impact performance. Always back up data before making changes.