MySQL5.6の文字コード設定が分からない
環境:Vagrant上のUbuntu14.04
MySQLはapt-get install
で入れた5.5
をhttp://dev.mysql.com/get/mysql-apt-config_0.8.0-1_all.deb
を使って5.6
にアップグレードした。
文字コードを全部utf8mb4
にしようとしていて、設定はすべて/etc/mysql/my.cnf
に書いた。
作業しているOSユーザがroot
の場合は希望通りの設定となっていたのだが、別のOSユーザでDB接続した際には設定が違っていてびっくりした。
OSユーザが違うことで適用される設定が変わるとかあるのでしょうか……?
tusui@hogehoge:~$ sudo su - root root@hogehoge:~# mysql -uroot -p
rootユーザで接続すると
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like '%character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8mb4 | | character_set_connection | utf8mb4 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8mb4 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) mysql> show variables like '%collat%'; +----------------------+--------------------+ | Variable_name | Value | +----------------------+--------------------+ | collation_connection | utf8mb4_general_ci | | collation_database | utf8mb4_general_ci | | collation_server | utf8mb4_general_ci | +----------------------+--------------------+ 3 rows in set (0.00 sec)
utf8mb4
ベースになっている。
tusui@hogehoge:~$ mysql -uroot -p
とroot
じゃないOSユーザで接続すると
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like '%character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) mysql> show variables like '%collat%'; +----------------------+--------------------+ | Variable_name | Value | +----------------------+--------------------+ | collation_connection | utf8_general_ci | | collation_database | utf8mb4_general_ci | | collation_server | utf8mb4_general_ci | +----------------------+--------------------+ 3 rows in set (0.00 sec)
なぜ……?
この状態からset names utf8mb4
すると、root
ユーザと同じ設定になる。
追記
次の日、vagrant up
してroot
ユーザ以外で接続すると、期待通りのcharacter set、collationになっていたとさ……。