mysqlに接続
***********@mbp ***** % mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28 Homebrew
Copyright (c) 2000, 2022, 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 |
+---------------------------+
| ******_development |
| ******_review_development |
| ******_review_test |
| ******_test |
| information_schema |
| mysql |
| performance_schema |
| sys |
| training |
+---------------------------+
9 rows in set (0.00 sec)
******_developmentのデータベースを表示させる
失敗
mysql> show ******_development
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garden_development' at line 1
成功
mysql> show tables from ******_development;
+------------------------------+
| Tables_in_******_development |
+------------------------------+
| a |
| h |
| l |
| p |
| p |
| s |
| u |
| v |
+------------------------------+
8 rows in set (0.00 sec)
データベースの中のテーブルのカラムの情報を表示させる。
mysql> SHOW COLUMNS FROM ******* FROM ******_development;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | tinyint | NO | PRI | NULL | |
| name | varchar(50) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
テーブルの抽出をする
失敗
mysql> select * from *********;
ERROR 1046 (3D000): No database selected
成功 useでデータベースを対象にしてから抽出作業に移る
mysql> use ******_development;
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> select * from *******;
+----+--------------+
| id | name |
+----+--------------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
+----+--------------+
4 rows in set (0.01 sec)
感想
当たり前のことだけど忘れていた。
また同じ内容の記事をあげそうだ。