Skip to content
Advertisement

Automate mysql_secure_installation with echo command via a shell script

I am trying to automate mysql_secure_installation script with automated response. My code is as follows :

echo "& y y abc abc y y y y" | ./usr/bin/mysql_secure_installation

The actual questions which i am automating are as follows:

Enter current password for root (enter for none): <enter>
Set root password? [Y/n] y
New password: abc
Re-enter new password: abc
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

But it gives me an error “Sorry you cannot use an empty password here” but in the screen i used to press the return key for the first question.

Advertisement

Answer

You can try to use expect, that automates interactive applications. Look at this automating mysql_secure_installation or at my modification.

Advertisement