Created
May 13, 2014 01:01
-
-
Save masarufuruya/64830a4ccc86f0abd6a7 to your computer and use it in GitHub Desktop.
MySQLでよく使うコマンド一覧まとめ ref: http://qiita.com/masarufuruya/items/9ff82e885709980ded0e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select host,user from mysql.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysqlにログインしてselect version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
truncate table テーブル名 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysqldump -u root -p データベース名 > test.sql | |
特定のテーブルをダンプする | |
mysqldump -u root -p データベース名 テーブル名 > test.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql -u root -p データベース名 < test.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alter table テーブル名 rename as 新テーブル名 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alter table テーブル名 change column 既存の列名 新しい列名 型名 制約 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe テーブル名 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create database testdb; | |
grant all on testdb.* to root@localhost identified by 'hogehoge'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop database 〜 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table テーブル名 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select * from tweets; | |
select * FROM tweets WHERE UID='nak'; | |
select * FROM tweets WHERE MESSAGE LIKE 'he%'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert into tweets | |
('TID','UID','MESSAGE','DATEOFMSG') | |
values('1','nak','oraora','2012-10-22'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update tweets set | |
message='おらおら' where uid='nak'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delete from tweets where uid='wo2'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment