Bug #53796 mysql_secure_installation should allow untattended installation
Submitted: 19 May 2010 11:04 Modified: 4 Feb 2013 4:53
Reporter: Daniël van Eeden Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.5.4 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, patch

[19 May 2010 11:04] Daniël van Eeden
Description:
mysql_secure_installation requires an interactive session. 

A unatteded/silent install should be possible.

How to repeat:
Try to run mysql_secure_installation from a script.

Suggested fix:
This fix is NOT yet complete as set_root_password still asks questions.

--- mysql_secure_installation.sh.orig	2010-05-19 12:50:01.158020000 +0200
+++ mysql_secure_installation.sh	2010-05-19 12:57:28.634544000 +0200
@@ -203,6 +203,17 @@
 
 # The actual script starts here
 
+if [ "$1" = "--noask" ]; then
+  echo "Running mysql_secure_installation in no ask mode"
+  set_root_password
+  remove_anonymous_users
+  remove_remote_root
+  remove_test_database
+  reload_privilege_tables
+  cleanup
+  exit 0
+fi
+
 prepare
 set_echo_compat
[19 May 2010 13:35] Daniël van Eeden
This workaround could be used:

#!/usr/bin/expect --
spawn /usr/local/mysql/bin/mysql_secure_installation

expect "Enter current password for root (enter for none):"
send "\r"
	
expect "Set root password?"
send "y\r"

expect "New password:"
send "password\r"

expect "Re-enter new password:"
send "password\r"

expect "Remove anonymous users?"
send "y\r"

expect "Disallow root login remotely?"
send "y\r"

expect "Remove test database and access to it?"
send "y\r"

expect "Reload privilege tables now?"
send "y\r"

puts "Ended expect script."
[19 May 2010 15:11] Valeriy Kravchuk
Thank you for the problem report and suggested patch and workaround.
[4 Feb 2013 4:53] Erlend Dahl
We believe this was taken care of in 5.6.8 through the --random-passwords option to mysql_install_db:

http://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-8.html
[11 Sep 2014 12:02] Lenz Grimmer
Actually, the changes to mysql_install_db do *not* resolve the issues described here. It's still not possible to run mysql_secure_installation in an unattended fashion.
[15 Sep 2014 14:38] Daniël van Eeden
Please change the status to Open or Verified per the comment from Lenz. I can't change it myself as this bug was filed with my previous account.