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 1 year has passed since last update.

macでmysqlをはじめのはじめ

Posted at

記事でわかること

mysqlでハローワールドが作れる

前提

brewが入っている

やり方 Mysqlを起動

ターミナルからbrewでmysqlをインストール

brew install mysql

インストールできたかのバージョンで確認

mysql --version

image.png

サーバーを起動

mysql.server start

ログインする

mysql -uroot

mysql>
となっていたら成功
image.png

Mysqlを使う

現在、存在しているデータベースを確認

show databases;

image.png

新規でデータベースを作る

create database test_db;

もう一度show で追加されたか確認する
image.png

テーブル作成

作ったdatabaseを選択

use test_db;

image.png

テーブルを作成

create table test_table (id INT AUTO_INCREMENT, name TEXT, PRIMARY KEY (id));

細かい説明は下記の補足を参照

テーブルを確認

show tables;

image.png

データを追加

insert into test_table(name) values('ハローワールド');

データを確認

select * from test_table;

image.png

やったね

テーブル作成時の補足

create table test_table (id INT AUTO_INCREMENT, name TEXT, PRIMARY KEY (id));

create table : テーブル作成命令
test_table : テーブル名
id INT AUTO_INCREMENT : idというカラム名でデータはint(整数)、自動でインクリメントされる
name TEXT : nameというカラム名でデータは文字列
PRIMARY KEY(id) : id を重複なしのデータに設定

参考サイト

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?