読者です 読者をやめる 読者になる 読者になる

AKAI TSUKI

System development or Technical something

set character in MySQL

データベースを作ったりする前に、my.cnfの文字コード設定を変えておいた方がよいので。

UTF-8にします。

# service mysqld stop
mysqld を停止中:                                           [  OK  ]
# diff /etc/my.cnf.org /etc/my.cnf
22a23,25
> # character
> character-set-server=utf8
>
# service mysqld start
mysqld を起動中:                                           [  OK  ]
#

設定されたことを確認します。
MySQLに接続して。

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)

mysql>

sampleデータベースを作成します。

mysql> create database sample;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sample             |
+--------------------+
4 rows in set (0.00 sec)

mysql> show create database `sample`;
+----------+-----------------------------------------------------------------+
| Database | Create Database                                                 |
+----------+-----------------------------------------------------------------+
| sample   | CREATE DATABASE `sample` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>