0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[mysql] ログイン~table新規作成

Posted at

自分用メモ

まだサーバにmysql入れてないって方はこちら

まずはDBまでたどり着く

ログイン

shell
mysql -u ユーザ名 -p データベース名

DB一覧表示で、目的のDBがあるか確認

mysql
show databases;

目的のDBを見つけたらそのDBに移動する。

mysql
use データベース名;

テーブルを作成する

作成前に、table名がダブらないよう、table一覧表示で確認

mysql
show tables;

いよいよ作成!

mysql
create table テーブル名(
列名1 データ型1 [オプション],
列名2 データ型2 [オプション],
列名3 データ型3 [オプション]
);

作成例はこちら

テーブル名:item
列1:「id」数値型
列2:「name」可変文字型(127文字ぐらい) 空白無
列3:「display」数値型 空白無
※自動連番には必ずインデックスを設定する

上記定義なら、以下のようになる。

mysql
create table item(
 id int,
 name varchar(127) not null,
 display int not null,
);

ちゃんと作成できたか確認

mysql
desc テーブル名;

最後に忘れずにログアウトしよう

mysql
exit;

以上!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?