1
3

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.

ターミナルからSQL文を使ってmysqlでデータベース、テーブルを作る方法

Posted at

ターミナルからmysqlに接続する方法

mysql -u ユーザー名

データベースを一覧で表示する

SHOW DATABASES;

※SQL文の終わりには;(セミコロンが必要)

データベースの作成方法

CREATE DATABASE データベース名;

※SQL文の終わりには;(セミコロンが必要)

データベースを選択する

USE データベース名;

データベースに存在するテーブルを一覧で表示する

SHOW TABLES;

テーブルの作成

CREATE TABLE テーブル名 (カラム名 カラム名の型, カラム名 カラム名の型,...);

| 型名 |値|
|:-----------------:|:------------------:|:------------------:|
| INT | 数字 |
|  VARCHAR(M)   | 最大M文字の文字列|

カラムの追加

ALTER TABLE テーブル名 ADD (カラム名 カラム型, カラム名 カラム型,....);

カラム名の修正

ALTER TABLE テーブル名 CHANGE 古いカラム名 新しいカラム名 新しいカラム型;

※カラム型は変わらなくても必ず記述する必要がある

カラム名の削除

ALTER TABLE テーブル名 DROP カラム名;
1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?