I am writing a script where I am want to launch the
mysql_secure_installation script and provide the appropriate answers at each prompt. I tried using echo like this:
echo -e "\n\n$db_pass\n$db_pass\n\n\n\n\n" | /usr/bin/mysql_secure_installation
It doesn’t work completely. It seems that it answers the last 5 questions correctly but it doesn't answer the first 3 correctly (this is on a
CentOS 6.5 box). Here is the output:
In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. stty: standard input: Invalid argument Enter current password for root (enter for none): stty: standard input: Invalid argument OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] ... skipping.
It should submit a return when asked for the root password. Then it should submit another return when asked to set the root password. However, as you can see from the output that is not happening.
What do I need to do in order to get this to work as expected?