LoginSignup
1
0

More than 5 years have passed since last update.

mysql データベース 色々

Posted at

mysql いろいろコマンド

1,データベースの作成
CREATE DATABASE board_db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

2,データベースの選択
use board_db;

3,ユーザの作成
GRANT ALL PRIVILEGES ON board_db.* TO board_user@localhost IDENTIFIED BY 'board_pass' WITH GRANT OPTION;

4,テーブルの作成
create table board(
id int not null auto_increment primary key,
name varchar(20),
comment text
)

5,テーブルの構造確認
desc board;

6,データを入力する
insert into テーブル名 (カラム名1, カラム名2, ...) values ( '値1', '値2', ...);
insert into board ( name, comment ) values ( 'matsumoto' ,'test' );

7,データを検索する
select カラム名 from テーブル名 where 条件文;
select id, name, comment from board;
例えばid=100のデータだけをとってきたい場合
select id, name, comment from board where id = 100;

8,データを更新する
update テーブル名 set カラム名 = '変更したい値' where 条件文;
update board set comment = 'test2' where id = 1;

9,データを削除する
delete from テーブル名 where 条件文;
delete from board where id = 1;

1
0
2

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
0