View Single Post
Old 02-02-2013, 12:45 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
By the by, if you have an existing table that has been specified wrongly, you *CAN* alter it.

How to tell? Use the SHOW CREATE TABLE yourtablename; command.

It will dump out the table and show you the CHARSET default for the entire table and the character set of each field, if different than the table default.

For example:
Code:
mysql> show create table xxx;
+-------+----------------------------------------
| Table | Create Table
+-------+----------------------------------------
| xxx   | CREATE TABLE `xxx` (
  `name` varchar(100) DEFAULT NULL,
  `email` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------
Okay, so that table has two fields and both use the DEFAULT for the table character set of "latin1".

So I can do:
Code:
mysql> alter table xxx modify name varchar(100) charset utf8;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table xxx;
+-------+--------------------------------------------------------------------
| Table | Create Table
+-------+--------------------------------------------------------------------
| xxx   | CREATE TABLE `xxx` (
  `name` varchar(100) CHARACTER SET utf8 DEFAULT NULL,
  `email` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------
See? The table still defaults to "latin1"--and that means the EMAIL field will be "latin1". But the NAME field is now UTF8 and so can hold Unicode characters.

Easy with MySQL!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Eggweezer (02-02-2013)