Debugging and other tools
Stay organized with collections
Save and categorize content based on your preferences.
Overview
This page includes scripts that help with debugging and using MySQL.
Find write activities
#!/bin/bash
# Tail the binlog and look for insert / update / delete
# The goal is to help the user understand which writes are happening
MYSQL=$(whichmysql)
MYSQLBINLOG=$(whichmysqlbinlog)
DATE=$(whichdate)
if[[-z"${MYSQL}"]]
then
echo"ERROR: Could not find mysql shell"
exit1
fi
if[[-z"${MYSQLBINLOG}"]]
then
echo"ERROR: Could not find mysqlbinlog utility"
exit1
fi
if[[-z"1ドル"]]
then
echo"Usage: 0ドル [mysql connection parameters]"
exit1
fi
last_log=$("${MYSQL}""$@"-N-B-e"SHOW BINARY LOGS;"|tail-n1|cut-f1)
time=$("${DATE}"'+%Y-%m-%d %H:%M:%S')
echo"Continuously reading from ${last_log} starting from ${time}"
"${MYSQLBINLOG}"--base64-output=DECODE-ROWS--verbose--start-datetime="${time}"--read-from-remote-server"$@""${last_log}"--stop-never|grep"INSERT\|UPDATE\|DELETE"
Find ALTER TABLE commands
#!/bin/bash
# Search for DDL Commands in the last 24 hours. Should help the user understand
# which DDL commands they are performing.
MYSQL=$(whichmysql)
MYSQLBINLOG=$(whichmysqlbinlog)
DATE=$(whichdate)
if[[-z"${MYSQL}"]]
then
echo"ERROR: Could not find mysql shell"
exit1
fi
if[[-z"${MYSQLBINLOG}"]]
then
echo"ERROR: Could not find mysqlbinlog utility"
exit1
fi
if[[-z"1ドル"]]
then
echo"Usage: 0ドル [mysql connection parameters]"
exit1
fi
log_files=$("${MYSQL}""$@"-N-B-e"SHOW BINARY LOGS;"|cut-f1)
yesterday=$("${DATE}"--date="-1 day"'+%Y-%m-%d %H:%M:%S')
echo"Searching for DDL commands, starting at ${yesterday}"
forfilein${log_files}
do
echo"Log file: ${file}"
"${MYSQLBINLOG}"--start-datetime"${yesterday}"--read-from-remote-server"$@""${file}"|grep-B2"ALTER TABLE\|CREATE TABLE\|TRUNCATE TABLE\|RENAME TABLE\|DROP TABLE"
done
Lock all tables
#!/bin/bash
# This script locks all non-system tables on a MySQL database.
# Helps for the case where we cannot acquire read lock with flush.
MYSQL="$(whichmysql)"
if[[-z"${MYSQL}"]]
then
echo"ERROR: Could not find mysql shell"
exit1
fi
if[[-z"1ドル"]]
then
echo"Usage: 0ドル [mysql connection parameters]"
exit1
fi
LOCK_TABLES_STMT="select concat('LOCK TABLES ', group_concat(concat('\`',table_schema,'\`.\`',table_name,'\` READ')),';') as stmt from information_schema.tables where table_schema not in ('mysql', 'sys', 'performance_schema', 'information_schema');"
QUERY="$("${MYSQL}""$@"-N-B-e"${LOCK_TABLES_STMT}")"
(
echo"${QUERY}"
read-n1-r-s-p$'Tables locked, press any key to stop the session and UNLOCK TABLES\n'
echo"UNLOCK TABLES;"
)|"${MYSQL}""$@"
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025年10月29日 UTC.