1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

自分のDockerでのMySQLの使い方

Last updated at Posted at 2017-03-12

特に細かい設定をしないのでmy.cnfなしでutf8mb4で起動させる。

起動

docker run -d -p 60001:3306 --name mysql5.6.23 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:5.6.23 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci

接続

docker run -it --link mysql5.6.23:mysql --rm mysql:5.6.23 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot --default-character-set=utf8mb4'

接続する時に、--default-character-set=utf8mb4を付けないとlatin1になってしまうので注意。

mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| 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)

クライアントコンテナのmy.cnfutf8mb4に設定していれば良いのかも知れないが、なくてもこれだけでutf8mb4で繋げるのでこうして使っている。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?