Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
37
Help us understand the problem. What is going on with this article?
@TakashiOshikawa

Dockerコンテナ内に入らずにMySQL公式コンテナの中にSQL等を実行するメモ

More than 3 years have passed since last update.

MacからMySQLコンテナ内にコマンドを実行したかったり、SQLを実行したい時などに使うコマンドをメモっておきます

MySQLコンテナ起動

docker run --name container_mysql -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mysql

MySQLコンテナ接続

docker exec -it container_mysql bash

Macから直接コンテナ内のMySQLに接続する

docker exec -it container_mysql mysql -u user -p

MacからコンテナのMySQLにローカルのMySQLコマンドで接続する

mysql -h$(docker-machine ip iti-dev) -P 3306 -u root -p

Macから直接指定したDBにクエリを発行する

docker exec -it container_mysql mysql -u user -p database_name -e"create table kkk (id int);"

Macから直接SQLファイルを実行する

docker exec -it container_mysql mysql -u user -p database_name -e"$(cat xxx.sql)"

// またはこちら ※passwordが履歴に残ってしまうけど
cat jjj.sql | docker exec -i container_mysql mysql -u root -ppassword database_name
37
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
37
Help us understand the problem. What is going on with this article?