#!/bin/sh
#
# mysql-after-setup
# Copyright (c) 2006 Alexey Tsvetnov, vorakl@fbsd.kiev.ua
# Version: 1.1
#
# Run script after install MySQL to do:
# 1. Drop database 'test'
# 2. Set MySQL root password
# 3. Delete all users and access except root@localhost
#echo -n "1. Drop database 'test'..." && \
mysqladmin -u root -f drop test > /dev/null && \
echo "delete from db where db like '%test%'" | mysql -u root mysql && echo "Ok."
echo "2. Set MySQL root password..."
# tty echo off
stty -echo
# enter correct password
while true
do
echo -n "Enter password: " && read pass1 && echo
echo -n "Re-enter password: " && read pass2 && echo
[ "${pass1}" = "${pass2}" ] && break
echo " *** Error!"
done
# tty echo on
stty echo
mysqladmin -u root -h localhost password $pass1 && echo "Ok."
echo -n "3. Delete all users and access except root@localhost... " && \
echo "delete from user where password=''" | mysql -u root -p$pass1 mysql && echo "Ok."
echo -n "4. Reload grant tables..." && \
mysqladmin -u root -p$pass1 -h localhost flush-privileges && echo "Ok."
exit 0
URL:
Обсуждается: https://www.opennet.ru/tips/info/1037.shtml