1

I need staff to make a shell script that installs mysql server with yum however need to install it sets the root password mysql automatically! Most do not know how to do this can anyone help me?

1 Answer 1

1

One way would be to specify the password afterwards (when you know the default)

mysqladmin -u root password <NEW_PASS>

You can try to make that part of your script.

The other way would be to use here-strings.

It will basically look something like this:

sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password <NEW_PASS>'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password <NEW_PASS>'
sudo apt-get -y install mysql-server

Third way would be to use a real provisioning framework like Chef or Puppet or other, where you use files to describe a certain type of node, similar to this:

class mysql-server {
     $password = "insert_password_here"
     package { "MySQL-client": ensure => installed }
     package { "MySQL-server": ensure => installed }
     package { "MySQL-shared": ensure => installed }

     exec { "Set MySQL server root password":
       subscribe => [ Package["MySQL-server"], Package["MySQL-client"], Package["MySQL-shared"] ],
       refreshonly => true,
       unless => "mysqladmin -uroot -p$password status",
       path => "/bin:/usr/bin",
       command => "mysqladmin -uroot password $password",
     }
}

Check out the full article here.

Further resources:

[1]Configuration management mysql with chef

[2]Configuration management mysql with Puppet

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.