Home >Database >Mysql Tutorial >How do you change the default character set of a MySQL table from latin1 to utf8?
MySQL allows you to specify a default character set for a table when it's created. By default, MySQL uses latin1 as the character set. However, you may need to change this to accommodate data in a different character set, such as utf8.
Consider the following MySQL table with a default character set of latin1:
<code class="sql">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;</code>
You want to change the default character set of this table to utf8.
To change the default character set of a table and its character columns to a new character set, use the following statement:
<code class="sql">ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;</code>
In this case, the query would be:
<code class="sql">ALTER TABLE etape_prospection CONVERT TO CHARACTER SET utf8;</code>
After executing this statement, the default character set of the etape_prospection table and all of its character columns will be changed to utf8.
The above is the detailed content of How do you change the default character set of a MySQL table from latin1 to utf8?. For more information, please follow other related articles on the PHP Chinese website!