Skip to content

Instantly share code, notes, and snippets.

@masarufuruya
Created May 13, 2014 01:01
Show Gist options
  • Save masarufuruya/64830a4ccc86f0abd6a7 to your computer and use it in GitHub Desktop.
Save masarufuruya/64830a4ccc86f0abd6a7 to your computer and use it in GitHub Desktop.
MySQLでよく使うコマンド一覧まとめ ref: http://qiita.com/masarufuruya/items/9ff82e885709980ded0e
select host,user from mysql.user
mysqlにログインしてselect version()
truncate table テーブル名
mysqldump -u root -p データベース名 > test.sql
特定のテーブルをダンプする
mysqldump -u root -p データベース名 テーブル名 > test.sql
mysql -u root -p データベース名 < test.sql
alter table テーブル名 rename as 新テーブル名
alter table テーブル名 change column 既存の列名 新しい列名 型名 制約
describe テーブル名
create database testdb;
grant all on testdb.* to root@localhost identified by 'hogehoge';
drop database 〜
create table if not exists users(
user_id INT AUTO_INCREMENT,
password VARCHAR(30) NOT NULL,
name VARCHAR(140) NOT NULL,
regist_date TIMESTAMP NOT NULL,
PRIMARY KEY(user_id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8;
drop table テーブル名
select * from tweets;
select * FROM tweets WHERE UID='nak';
select * FROM tweets WHERE MESSAGE LIKE 'he%';
select cm.club_name from club_master as cm where club_id
in(select uj.club_id from user_master as um inner join user_join_club as uj on um.user_id = uj.user_id)
select um.name_kanji,cm.club_name from user_master as um
inner join user_join_club as uj on um.user_id = uj.user_id
inner join club_master as cm on uj.club_id = cm.club_id
insert into tweets
('TID','UID','MESSAGE','DATEOFMSG')
values('1','nak','oraora','2012-10-22');
update tweets set
message='おらおら' where uid='nak';
delete from tweets where uid='wo2';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment