Difference between revisions of "Securing mysql with a script"

From MyWiki
Jump to: navigation, search
Line 23: Line 23:
 
     # Kill the anonymous users
 
     # Kill the anonymous users
 
     mysql -e "DROP USER ''@'localhost'"
 
     mysql -e "DROP USER ''@'localhost'"
     # Because our hostname varies we'll use some Bash magic here.
+
     # Because our hostname varies we\'ll use some Bash magic here.
 
     mysql -e "DROP USER ''@'$(hostname)'"
 
     mysql -e "DROP USER ''@'$(hostname)'"
 
     # Kill off the demo database
 
     # Kill off the demo database

Revision as of 12:47, 28 August 2017

Reference - https://stackoverflow.com/questions/24270733/automate-mysql-secure-installation-with-echo-command-via-a-shell-script

mysql_secure_installation <<EOF
 
y
secret
secret
y
y
y
y
EOF


not tested the sql script below

    #!/bin/bash
 
    # Make sure that NOBODY can access the server WITHOUT a password
    mysql -e "UPDATE mysql.user SET Password = PASSWORD('CHANGEME') WHERE User = 'root'"
    # KILL the anonymous users
    mysql -e "DROP USER ''@'localhost'"
    # Because our hostname varies we\'ll use some Bash magic here.
    mysql -e "DROP USER ''@'$(hostname)'"
    # Kill off the demo database
    mysql -e "DROP DATABASE test"
    # Make our changes take effect
    mysql -e "FLUSH PRIVILEGES"
    # Any subsequent tries to run queries this way will get access denied because lack of usr/pwd param