How to Modify MySQL Database Table Field Encoding

When loading data with LOAD DATA INFILE, garbled characters may appear. When using LOAD, the encoding of the database, table, and fields must match the file encoding. However, if the database already contains data and you don’t want to rebuild it, using commands to modify the encoding is a good option. Below is the fix. I tried modifying character_set_database = utf8 in my.ini, but it didn’t seem to work.

1. If the MySQL installation encoding cannot be changed 鈥?many friends who build websites on shared hosting don’t have permission to change the MySQL installation encoding 鈥?we can skip this step, because as long as the following steps are correct, the garbled character issue can still be resolved.
2. Modify the database encoding. If the database encoding is incorrect, you can execute the following command in phpMyAdmin: ALTER DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
The above command sets the encoding of the test database to utf8.
3. Modify the table encoding: ALTER TABLE `category` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
The above command changes the encoding of the category table to utf8.
4. Modify the field encoding:
ALTER

Leave a Comment

Your email address will not be published.