[Ruby] Edit Mysql using command in Docker environment

less than 1 minute read

Since Docker hasn’t been up for days yet for the first time, I’ll describe how to connect to Mysql in a terminal and play with it as a reminder.

At the beginning,

docker ps

Then, check the container ID of Mysql.

[email protected] APP_NAME% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2acfbade0963 app_name_web "rails s -p 3000 -b …" 2 days ago Up 2 days 0.0.0.0:3000->3000/tcp app_name
c71b0bf50f29 mysql:5.6.47 "docker-entrypoint.s…" 2 days ago Up 2 days 0.0.0.0:3306->3306/tcp app_name

Since it looks like this, copy “c71b0bf50f29” this time.

next,

docker exec -it container id mysql -u root -p

To connect to Mysql.

This time, paste the “c71b0bf50f29” that you just copied.

Since the password was written in database.yml, it’s OK

bonus

If you want to play with the table from there,

show databases;

Then, copy the database,

use DB name just copied

Check in table

select * from table name;

Delete all in table

DELETE FROM table-name;