mysqlでデータベースを作る
> mysql -urootで、mysqlのコマンドラインにログイン。> show databases;で、保有しているデータベースをチェックできる。mysql> create database miyagi_vactine;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || miyagi_vactine || mysql || performance_schema || sys |+--------------------+5 rows in set (0.00 sec)で、作成完了。赤字に注目。自分のデータベースの中に、テーブルを作る。まず、使用するデータベースの中にはいる。mysql> use miyagi_vactine;Database changedCREATE TABLEコマンドで、テーブル名"users"を作り、usersの要素を指定する。mysql> create table users(id INT AUTO_INCREMENT, -> name text, -> mobile text, -> add1 text, -> add2 text, -> sex text, -> blood text, -> comments text, -> PRIMARY KEY (id));Query OK, 0 rows affected (0.01 sec)できたテーブルを見ると、mysql> show tables;+--------------------------+| Tables_in_miyagi_vactine |+--------------------------+| users |+--------------------------+1 row in set (0.00 sec)テーブルの中身を見る。mysql> describe users;+----------+------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------+------+------+-----+---------+----------------+| id | int | NO | PRI | NULL | auto_increment || name | text | YES | | NULL | || mobile | text | YES | | NULL | || add1 | text | YES | | NULL | || add2 | text | YES | | NULL | || sex | text | YES | | NULL | || blood | text | YES | | NULL | || comments | text | YES | | NULL | |+----------+------+------+-----+---------+----------------+8 rows in set (0.00 sec)idの所にある、auto_incrementは、idをprimary keyと指定して、同じ数字が入らないように規制したので、idに入れる時自動的に数値が増加する設定になっている。とりあえず、これで準備は完了。あ、タイムスタンプ忘れていたので、追加する。mysql> alter table users add(timestamp text);Query OK, 0 rows affected (0.01 sec)Records: 0 Duplicates: 0 Warnings: 0mysql> describe users;+-----------+------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-----------+------+------+-----+---------+----------------+| id | int | NO | PRI | NULL | auto_increment || name | text | YES | | NULL | || mobile | text | YES | | NULL | || add1 | text | YES | | NULL | || add2 | text | YES | | NULL | || sex | text | YES | | NULL | || blood | text | YES | | NULL | || comments | text | YES | | NULL | || timestamp | text | YES | | NULL | |+-----------+------+------+-----+---------+----------------+9 rows in set (0.01 sec)これで、完了。https://prog-8.com/docs/mysql-database-setup