Home > Database > Mysql Tutorial > body text

How to Change the Character Set of a MySQL Table from \'latin1\' to \'utf8\'?

Susan Sarandon
Release: 2024-10-27 10:19:03
Original
745 people have browsed it

How to Change the Character Set of a MySQL Table from 'latin1' to 'utf8'?

How to Alter the Character Set of a MySQL Table

In the context of SQL, character sets define the encoding used to store and retrieve data containing characters from various languages and scripts. The default character set for a MySQL table is 'latin1', which supports Western European characters. However, there are situations where you may need to change this character set to accommodate different language requirements.

To illustrate this, we have a MySQL table called 'etape_prospection' with the following definition:

CREATE TABLE `etape_prospection` (
     `etape_prosp_id` int(10) NOT NULL AUTO_INCREMENT,
     `type_prosp_id` int(10) NOT NULL DEFAULT '0',
     `prosp_id` int(10) NOT NULL DEFAULT '0',
     `etape_prosp_date` datetime DEFAULT NULL,
     `etape_prosp_comment` text,
     PRIMARY KEY (`etape_prosp_id`),
     KEY `concerne_fk` (`prosp_id`),
     KEY `de_type_fk` (`type_prosp_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
Copy after login

The requirement is to alter the default character set of this table from 'latin1' to 'utf8' to support a wider range of characters. This can be achieved using the following SQL statement:

ALTER TABLE etape_prospection CONVERT TO CHARACTER SET utf8;
Copy after login

By executing this statement, you will convert the default character set of the 'etape_prospection' table to 'utf8'. This change will ensure that both the table structure and the data within it are stored and processed using the 'utf8' character encoding, allowing for a richer representation of characters from diverse languages and scripts.

The above is the detailed content of How to Change the Character Set of a MySQL Table from \'latin1\' to \'utf8\'?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!