How to make MySQL handle UTF-8 properly

前端 未结 14 2827
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:38

One of the responses to a question I asked yesterday suggested that I should make sure my database can handle UTF-8 characters correctly. How I can do this with MySQL?

14条回答
  •  再見小時候
    2020-11-22 07:06

    The charset is a property of the database (default) and the table. You can have a look (MySQL commands):

    show create database foo; 
    > CREATE DATABASE  `foo`.`foo` /*!40100 DEFAULT CHARACTER SET latin1 */
    
    show create table foo.bar;
    > lots of stuff ending with
    > ) ENGINE=InnoDB AUTO_INCREMENT=252 DEFAULT CHARSET=latin1
    

    In other words; it's quite easy to check your database charset or change it:

    ALTER TABLE `foo`.`bar` CHARACTER SET utf8;
    

提交回复
热议问题