Change default charset for new databases
Posted by: taggen (---.tbcn.telia.com)
Date: May 07, 2025 08:41PM

How do I change the default charset from latin1_swedish_ci to utf8mb4_unicode_ci?

/ taggen
"Too old to die young"

Options: ReplyQuote
Re: Change default charset for new databases
Posted by: Otomatic (Moderator)
Date: May 08, 2025 08:59AM

When creating a database, for example using PhpMyAdmin, you can specify the charset.
When creating a table, you can specify the charset and even when creating columns.

See MySQL charsets and collations

But none of this has anything to do directly with Wampserver.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Change default charset for new databases
Posted by: Castspeller (---.hsd1.ca.comcast.net)
Date: May 11, 2025 10:10PM

Please make sure to make a backup of the file you will be modifying in case you need to revert back.

1. Stop WampServer which will stop MariaDB.
2. Change the my.ini to add these lines under [mysqld] (Do not put the lines with dashes:

---
character_set_server=utf8mb4
collation_server=utf8mb4_unicode_ci
---

3. Start WampServer

Volia! Any NEW databases will be with this character set.

PLEASE NOTE!!! Databases that were already created will need to be manually converted to the new character set. Before attempting that make sure your have TWO backups (for safety). I suggest reading MariaDB's documentation on how to do that.

Cheers

Options: ReplyQuote
Re: Change default charset for new databases
Posted by: Otomatic (Moderator)
Date: May 12, 2025 11:13AM

The following query will transcode the table to accept four-byte utf8 characters, without any loss of datas. It is essential to specify the names of the columns to be transcribed)

ALTER TABLE t1
  DEFAULT CHARACTER SET utf8mb4,
  MODIFY col1 CHAR(10)
    CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  MODIFY col2 CHAR(10)
    CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;

More simply, you can use :

ALTER TABLE t1
  CONVERT TO CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
You don't have to give the column names; only those columns requiring transcoding will be transcoded automatically.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote


Sorry, only registered users may post in this forum.