文字コードをUTF-8に変更する。

■既存DBの変更

$>mysql -u root -p
Password:
mysql> set names utf8;


■設定
[mysqld]

default-character-set=utf8 ←追加
character_set_server=utf8 ←追加

[mysql]

default-character-set=utf8 ←追加


■再起動

$> sudo /etc/init.d/mysql restart

■確認

mysql> show variables like 'character%';
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       | 
| character_set_connection | utf8                       | 
| character_set_database   | utf8                       | 
| character_set_filesystem | binary                     | 
| character_set_results    | utf8                       | 
| character_set_server     | utf8                       | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+
8 rows in set (0.00 sec)



既存のデータベース、テーブルを変更する場合は、ALTER 〜で変更する。
↓↓↓

mysql>alter database [データベース名] default character set utf8
mysql>use [データベース名]
mysql>alter table [テーブル名] charset=utf8

例)既存のテーブルの設定変更

mysql>show create table auth_group \G
*************************** 1. row ***************************
       Table: auth_group
Create Table: CREATE TABLE `auth_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(80) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

mysql>alter table auth_group default charset=utf8;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>show create table auth_group \G
*************************** 1. row ***************************
       Table: auth_group
Create Table: CREATE TABLE `auth_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(80) CHARACTER SET latin1 NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)



参考になったら、ポチッとお願いします。m(_ _)m
↓↓↓
人気ブログランキングへ