ローカル開発環境にDockerの公式イメージを使っているが、mysqlのコマンドから日本語を入力したり、コピペしても消えてしまって困った。
https://hub.docker.com/_/mysql
文字コードはUTF−8。
日本語の表示は文字化けするけど
set names utf8;
で表示できる。毎回打つのはちょっと面倒だ。
docker-compose.ymlはこんな感じ。いろいろ省略してる
version: '3' services: mysql: container_name: mysql image: mysql:5.7 ports: - "3306:3306"
入るときはこんな感じ
$ docker-compose exec mysql mysql -u root -p
もちろんアプリケーション側では日本語は問題なく使えている。
主に手作業INSERTするときに困った。
検索するといろいろインストールしたり、localeとか設定する方法が出てくるのが面倒。
面倒なのでローカル(Mac)にmysqlクライアントをインストールした。
普通にHomebrewでいれる。サーバーはいらない。
https://qiita.com/takepan/items/e01dfd968faffbe2ebb2
$ brew install mysql-client
あとはこんな感じで入る。
$ mysql -h 127.0.0.1 -P 3306 -u root -p******* mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.29 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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> あああ
無事エンターしても消えずに入力できた。
もちろん本番環境では手作業INERTをはじめとして、こんなのおすすめできない。