The following commands for working with MySQL are summarized.
・ Login to MySQL ・ Display database list ・ Display table list ・ Display column list
mysql -u username-p
After entering, enter the password. Be careful not to make a mistake because the password is not displayed on the CLI.
Although deprecated, you can log in with a single shot by passing the password in the -p argument.
SHOW DATABASES;
The list is displayed like this.
mysql> SHOW databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| myapp_development |
| myapp_test |
| mysql |
| performance_schema |
| root |
| sys |
+--------------------+
7 rows in set (0.00 sec)
First, select the database you want to use.
use database name;
ex)use users;
SHOW TABLES;
You can get a list of tables in the database.
mysql> SHOW TABLES;
+----------------------+
| Tables_in_myapp_test |
+----------------------+
| posts |
| schema_migrations |
| users |
+----------------------+
3 rows in set (0.01 sec)
show tables from database name;
You can get it at.
Select the database as before. Execute the following command.
DESCRIBE table name;
show columns from table name;
ex)show columns from users;
You can get the column list in the table like this.
mysql> show columns from users;
+-----------------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | UNI | NULL | |
| created_at | datetime | NO | | NULL | |
| updated_at | datetime | NO | | NULL | |
| name | varchar(255) | NO | | NULL | |
| image | varchar(255) | YES | | NULL | |
+-----------------------------+--------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
-Launch the container with docker-compose up. -Docker-compose exec db bash -Connect to the DB container with mysql -u username -p
・ Launch a task ・ Connect to EC2 with ssh -Docker exec -it container ID sh · Mysql -h endpoint -u username -p to connect to RDS
Recommended Posts