patternsqlMinor
Check all MySQL tables at once
Viewed 0 times
oncetablesallmysqlcheck
Problem
I'd like to run a
I can do it for a single table:
Is there an equivalent command that would check all tables in the current database?
CHECK TABLE on all my tables from the MySQL command-line.I can do it for a single table:
mysql> check table Restaurant;
+--------------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+--------------------+-------+----------+----------+
| foodbox.Restaurant | check | status | OK |
+--------------------+-------+----------+----------+
1 row in set (0.02 sec)Is there an equivalent command that would check all tables in the current database?
Solution
You could simplify your life with a shell script. Here is one I created for Linux, it is based on the mysqlcheck application
This script will check all tables in all databases except mysql and information_schema
Save the file
Then execute it
For Windows you would use a batch script or vbs to do the same thing.
The other option would be just to run the mysqlcheck application for the one database you are interested in checking.
/path/to/mysqlcheck -u username -pPASSWORD -c database_name
mysqlcheck will be in the directory you installed your mysql binary files in.
In Linux, you can locate it with the which command
This script will check all tables in all databases except mysql and information_schema
vi check_all_databases.sh
#!/bin/bash
USER=root
Port=3306
PASSWD=password
DBS="$(/usr/bin/mysql --connect_timeout 10 -u $USER -P $Port -p$PASSWD -Bse 'SHOW DATABASES')"
for db in $DBS
do
if [ "$db" != "mysql" ] && [ "$db" != "information_schema" ];
then
/usr/bin/mysqlcheck -u $USER -p$PASSWD -c $db
fi
doneSave the file
\wqThen execute it
sh check_all_databases.sh
dbt2.customer OK
dbt2.district OK
dbt2.history OK
dbt2.item OK
dbt2.new_order OK
dbt2.order_line OK
dbt2.orders OKFor Windows you would use a batch script or vbs to do the same thing.
The other option would be just to run the mysqlcheck application for the one database you are interested in checking.
/path/to/mysqlcheck -u username -pPASSWORD -c database_name
mysqlcheck will be in the directory you installed your mysql binary files in.
In Linux, you can locate it with the which command
which mysqlcheckCode Snippets
vi check_all_databases.sh
#!/bin/bash
USER=root
Port=3306
PASSWD=password
DBS="$(/usr/bin/mysql --connect_timeout 10 -u $USER -P $Port -p$PASSWD -Bse 'SHOW DATABASES')"
for db in $DBS
do
if [ "$db" != "mysql" ] && [ "$db" != "information_schema" ];
then
/usr/bin/mysqlcheck -u $USER -p$PASSWD -c $db
fi
donesh check_all_databases.sh
dbt2.customer OK
dbt2.district OK
dbt2.history OK
dbt2.item OK
dbt2.new_order OK
dbt2.order_line OK
dbt2.orders OKwhich mysqlcheckContext
StackExchange Database Administrators Q#52807, answer score: 5
Revisions (0)
No revisions yet.