您好,登錄后才能下訂單哦!
有時候早期建的表上可能缺少主鍵,這樣容易導致查詢或者主從復制比較慢。
下面是一個小的腳本,用于找出沒有主鍵的表。
#!/bin/bash
# 找出沒有主鍵的表
# Date: 2017/06/05
source /etc/profile
LOG="/tmp/nopk.log_$(date +%F)"
user='root'
host='localhost'
pass='123456'
sock='/tmp/mysql.sock'
MYSQL_CMD="mysql -u$user -h$host -p$pass -S$sock"
dbs=$($MYSQL_CMD 2>/dev/null -BNe "select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME not in ('information_schema','performance_schema')")
for db in $dbs; do
$MYSQL_CMD information_schema 2>/dev/null -NBe "select distinct TABLE_SCHEMA,table_name from columns where TABLE_SCHEMA = '$db' and table_name not in ( select distinct table_name from COLUMNS where TABLE_SCHEMA = '$db' and (column_key = 'PRI' or column_key = 'UNI') )" | tee -a $LOG
done
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。