低レベルインフラエンジニアの忘備録

Linux系の各種作業を自分用の忘備録として残しています

MySQLデータベース・テーブル作成

(1)データベース作成

mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test_db |
+--------------------+
5 rows in set (0.00 sec)

mysql>

 

 

(2)テーブル作成

mysql> create table test_db.zaiko(id int auto_increment primary key,
-> maker text,
-> type text,
-> serial varchar(100),
-> purpose varchar(20),
-> input_date date,
-> output_date date,
-> index(id));
Query OK, 0 rows affected (0.27 sec)

mysql> use test_db;
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_test_db |
+-------------------+
| zaiko |
+-------------------+
1 row in set (0.00 sec)

mysql> SHOW COLUMNS FROM zaiko;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| maker | text | YES | | NULL | |
| type | text | YES | | NULL | |
| serial | varchar(100) | YES | | NULL | |
| purpose | varchar(20) | YES | | NULL | |
| input_date | date | YES | | NULL | |
| output_date | date | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql>