LoginSignup
0
0

More than 3 years have passed since last update.

SQLコマンドめも

Posted at

sqlファイル実行

cd [sqlのある場所]
mysql -uxxxx -pxxxx
mysql> source [sqlファイル名]

表示

  • 縦表示
select * from order where id = 123 \G;
  • 検索結果を | で区切りたい
SELECT
  GROUP_CONCAT(DISTINCT  concat_ws('|', code, name)  ORDER BY code separator '|')
FROM
  ...

# 結果
01|aaa|02|bbb|03|ccc

CSV

  • タブ出力
into outfile "/tmp/sample1.csv" fields terminated by '\t';

日時

  • 範囲指定

whereで日時の範囲を指定することがあるが

where rd.created_at >= '2015-04-01' and rd.created_at <= '2016-04-01' 

betweenでも指定できる

rd.created_at between '2015-04-01' and '2016-04-01' 

DB

  • トランザクション制御
start transaction;
SQL文
正常に終了したことを確認
commit;
  • ホスト名
mysql> show variables like 'hostname';
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