0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Bash MySQL】クエリの速度調査

0
Last updated at Posted at 2023-06-27

クエリの速度調査

変更箇所と記載されたところを各々書き換えれば、いい感じに速度調査できるはず。

sample.sh
#!/bin/sh

# MySQLの設定(変更箇所)
user="root"
pass="password"
endpoint="ここにエンドポイント"
database="sample_database"

# 実行したいクエリのパス(変更箇所)
query_path="./sample.sql"

# 同時に実行するクエリの数(変更箇所)
count=1

# 開始時刻計測
start_time=`date +%s.%N`

for i in $(seq 1 ${count}); do
  # バックグラウンドでクエリを叩く
  echo `mysql -u${user} -p${pass} -h${endpoint} ${database} < "${query_path}"` &
done

# 全ての処理が終わるまで待つ
wait

# 終了時刻計測
end_time=`date +%s.%N`

elapsed_time=$(echo "${end_time}" - "${start_time}" | bc)
echo "経過時間: ${elapsed_time}(s)"

以下は、スクリプト内で呼び出されるクエリ(調査対象)

sample.sql
SELECT SQL_NO_CACHE * FROM テーブル名;

SQL_NO_CACHEとは、クエリキャッシュを無効化してくれる便利なやつ(以下を参考に)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?