LoginSignup
4
4

More than 5 years have passed since last update.

mysqlコマンド早見表

Last updated at Posted at 2018-05-16

準備系

  項目       コマンド              例            
mysqlに接続     mysql -u root    -   
DB一覧を表示   show databases;    -
DB作成      create database 〇〇; CREATE DATABASE users(birth_day:int, email,varchar(255))
DB選択 use 〇〇;     USE users;

データ登録/更新/削除

  項目          コマンド                     例
登録
(カラム全て)
insert into 〇〇 values (値1,2,3...)     insert into users values (19930111,example@gmail.com,tanaka masashi,)
登録
(カラム一部)
insert into 〇〇 (カラム1,カラム2)
value(値1,値2)
insert into users (name, email)
 value (tanaka masashi, example@gmail.com)
変更 update 〇〇 set 変更内容 where 条件; update users set name = "suzuki masashi" where name = "tanaka masashi"
削除 delete from 〇〇 where 条件 delete from users where birth_day = 19930111

データ検索系

項目                コマンド
カラム選択   select               select name from users;
文字列合体 concat concat(family_name,first_name)from users;
カラムに命名 as concat(family_name,first_name) as "名前" from users
レコード数取得 count カラム名 select * from users count(*)
重複除外 distinct (中間テーブルなどで)select distinct user_id;
グループ化 group by (中間テーブルなどで)seelct user_id from posts group_by user_id
カラムの一致するデータ結合 join (中間テーブルなどで)select user_id, count(*)"投稿数" from posts p join users u on p.user_id = u.id group by user_id
4
4
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
4
4