mysql - Update Root passwords via Shell -


In a shell (.sh file) I am trying to update mysql password for "root".

At the moment I have this, is it safe and the right way? I do not want to signal.

I am also thinking that the accounts of "mysqladmin" and "mysql" are identical or not.

  User and pass for #Variables USER = "root" PASS = "test" mysqladmin -u root password $ PASS # Set root user password for all local domains sudo mysql --user = $ USER --password = $ PASS -e "root password @ localhost" '= password (' secret '); "Sudo mysql --user = $ USER --password = $ PASS -e" password for password @ 127.0.0.1 '= password (' secret '); "sudo mysql --user = $ USER --password = $ PASS-e "Set password for root @: 1 '= password (' secret ');" # leave any user sudo mysql --user = $ USER --password = $ PASS -e "DROP USER '' @ 'localhost'; "  

Update

With responses to tadman and b600 in mind. < p> So something like this would be a good idea?

To prevent that password, Shell will appear in history.

  # bootstrap.sh USER = "root" PASS = "test "sudo my Sqladmin -u root password $ PASS sudo mysql --user = $ USER --password = $ PASS-e & lt; /tmp/users.sql rm -f /tmp/users.sql # users.sql SET @password = secret ; DELETE * mysql.user where user is not 'root'; Set password for 'root @ localhost' = password (password); 'root @ 127.0.0.1' for SET PASSWORD = password (password); 'root Set password for @: 1 '= password (password);    

I recommend that you pass the password as a generated user on a local machine Generate and pass the hash to the password change command.

The password used in mysql is SHA1 according to hash, you can generate it using:

  echo-n password | Sha1sum | In addition, you can use 'password password' for  
  'url @ domain' password, personally, I do not like to keep plain text on the command line due to this fact Is that a non-recognized user can possibly see the password via password / Ptree / pstree command.   

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -