LoginSignup
0
0

More than 1 year has passed since last update.

MySQL 基本コマンド備忘録

Last updated at Posted at 2022-07-29

MySQLのコマンドの備忘録

適宜追加していきます

基本なもの

MySQLに入る

terminal
# mysql -u ユーザー名 -p
Enter password: パスワード

データベース作成

terminal
CREATE DATABASE 名前;

データベースの選択

terminal
USE 名前;

データベース一覧

terminal
SHOW databses;

データベースの権限を与える

MySQL8 の場合

terminal
grant all privileges on データベース名.* to 'ユーザー名'@'localhost';

MySQL5の場合

terminal
grant all on (データベース名).* to 'ユーザー名'@'localhost' identified by '設定したいパスワード';

設定できる権限は以下参照

テーブル作成 / 削除

作成
terminal
CREATE TABLE テーブル名 (
カラム名 型 その他
...
);

CREATE TABLE IF NOT EXISTS テーブル名 (
カラム名 型 その他
...
);

型一覧は長くなるため、別でまとめていきます(編集中)

if not exits を加えると、同じ名前のテーブルが存在したとしてもエラーにならない。

削除
terminal
DROP TABLE テーブル名;

テーブルの一覧

terminal
SHOW TABLES;

テーブルに値を挿入

terminal
INSERT 
テーブル名 (カラム名, カラム名, ...) 
VALUES(値1, 値2, ...),(値1, 値2, ...), ... ;

テーブルの中身

構造をみる。ともに結果は同じ。

terminal
DESC テーブル名;
SHOW COLUMNS FROM テーブル名;

値もみる

terminal
SELECT * FROM テーブル名
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