root@06e4cbc1e9ea:/# mysql -u naoki -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| todo |
+--------------------+
2 rows in set (0.02 sec)
データベース使用
mysql> use todo;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
テーブル
テーブルの一覧
mysql> show tables;
+----------------+
| Tables_in_todo |
+----------------+
| todos |
| users |
+----------------+
2 rows in set (0.00 sec)
カラム
カラム一覧
mysql> show columns from todos;
+------------+-------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | | NULL | |
| title | varchar(20) | YES | | NULL | |
| detail | text | YES | | NULL | |
| created_at | datetime | NO | | CURRENT_TIMESTAMP | |
| updated_at | datetime | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| delete_at | int(11) | YES | | NULL | |
| status | int(11) | NO | | NULL | |
+------------+-------------+------+-----+-------------------+-----------------------------+
8 rows in set (0.01 sec)
DBに入る
データベース
データベース一覧表示
データベース使用
テーブル
テーブルの一覧
カラム
カラム一覧
カラムの追加
下記はusersターブルにtokenカラム(NULL禁止、文字列)を追記するという意味