Automate mysql_secure_installation with echo command via a shell script

后端 未结 11 1044
无人共我
无人共我 2020-12-12 12:46

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/mysq         


        
11条回答
  •  孤城傲影
    2020-12-12 13:07

    I stumbled upon this question but decided to run the queries manually through a Bash script:

    #!/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
    

提交回复
热议问题