3
# This file is included by /etc/mysql/debian-start
6
## Check all unclosed tables.
7
# - Requires the server to be up.
8
# - Is supposed to run silently in background.
9
function check_for_crashed_tables() {
13
# But do it in the background to not stall the boot process.
14
logger -p daemon.info -i -t$0 "Triggering myisam-recover for all MyISAM tables"
16
# Checking for $? is unreliable so the size of the output is checked.
17
# Some table handlers like HEAP do not support CHECK TABLE.
19
# We have to use xargs in this case, because a for loop barfs on the
20
# spaces in the thing to be looped over.
21
LC_ALL=C $MYSQL --skip-column-names --batch -e '
22
select concat("select count(*) into @discard from `",
23
TABLE_SCHEMA, "`.`", TABLE_NAME, "`")
24
from information_schema.TABLES where ENGINE="MyISAM"' | \
25
xargs -i $MYSQL --skip-column-names --silent --batch \
26
--force -e "{}" >$tempfile
27
if [ -s $tempfile ]; then
30
"Improperly closed tables are also reported if clients are accessing\n" \
31
"the tables *now*. A list of current connections is below.\n";
32
$MYADMIN processlist status
34
# Check for presence as a dependency on mailx would require an MTA.
35
if [ -x /usr/bin/mailx ]; then
36
mailx -e -s"$MYCHECK_SUBJECT" $MYCHECK_RCPT < $tempfile
38
(echo "$MYCHECK_SUBJECT"; cat $tempfile) | logger -p daemon.warn -i -t$0
43
## Check for tables needing an upgrade.
44
# - Requires the server to be up.
45
# - Is supposed to run silently in background.
46
function upgrade_system_tables_if_necessary() {
50
logger -p daemon.info -i -t$0 "Upgrading MySQL tables if necessary."
52
# Filter all "duplicate column", "duplicate key" and "unknown column"
53
# errors as the script is designed to be idempotent.
56
| egrep -v '^(1|@had|ERROR (1054|1060|1061))' \
57
| logger -p daemon.warn -i -t$0
60
## Check for the presence of both, root accounts with and without password.
61
# This might have been caused by a bug related to mysql_install_db (#418672).
62
function check_root_accounts() {
66
logger -p daemon.info -i -t$0 "Checking for insecure root accounts."
68
ret=$( echo "SELECT count(*) FROM mysql.user WHERE user='root' and password='';" | $MYSQL --skip-column-names )
69
if [ "$ret" -ne "0" ]; then
70
logger -p daemon.warn -i -t$0 "WARNING: mysql.user contains $ret root accounts without password!"