0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

僕なりの docker-compose の備忘録

Last updated at Posted at 2024-05-16

MySQLコンテナが日本語対応していないときに、外からデータを流し込む

docker-compose exec -u $(id -u):$(id -g) mysql mysql -u user -ppassword -e 'クエリ'

run


exec

docker-compose exec -u $(id -u):$(id -g) <service-name> bash
docker-compose exec <service-name> bash -c "cd html/app && composer install"
docker-compose exec <service-name> bash -c "cd html/app && composer update"

docker-compose exec -u $(id -u):$(id -g) <service-name> bash -c "cd html/app && composer install"
docker-compose exec -u $(id -u):$(id -g) <service-name> bash -c "cd html/app && composer update"

docker-compose exec -u $(id -u):$(id -g) db bash
mysql -u user -ppassword -h db_service_name;
show databases;
create database my_database;
show grants for user;
GRANT ALL PRIVILEGES ON `my_database`.* TO `other_user`@`%`;

dockerコンテナのMySQLへログイン

docker-compose exec db bash -c 'mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE}'

文字コードの設定確認

rootユーザーで実行

mysql> show variables like '%char%';
+--------------------------+--------------------------------+
| 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     | utf8mb3                        |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)

ユーザーの確認

rootユーザーで実行

mysql> select Host, User from mysql.user;
+-----------+------------------+
| Host      | User             |
+-----------+------------------+
| %         | user            |
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
6 rows in set (0.01 sec)

バージョン確認

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.36    |
+-----------+
1 row in set (0.00 sec)

mysql> status
--------------
mysql  Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:          31
Current database:
Current user:           root@172.20.0.3
SSL:                    Cipher in use is TLS_AES_256_GCM_SHA384
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.36 MySQL Community Server - GPL
Protocol version:       10
Connection:             db via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
TCP port:               3306
Binary data as:         Hexadecimal
Uptime:                 14 min 14 sec

Threads: 2  Questions: 147  Slow queries: 0  Opens: 202  Flush tables: 3  Open tables: 121  Queries per second avg: 0.172
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?